Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1 | # Modern C++ use in Chromium |
| 2 | |
| 3 | _This document is part of the more general |
| 4 | [Chromium C++ style guide](https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++.md). |
| 5 | It summarizes the supported state of new and updated language and library |
| 6 | features in recent C++ standards and the [Abseil](https://abseil.io/about/) |
| 7 | library. This guide applies to both Chromium and its subprojects, though |
| 8 | subprojects can choose to be more restrictive if necessary for toolchain |
| 9 | support._ |
| 10 | |
| 11 | The C++ language has in recent years received an updated standard every three |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 12 | years (C++11, C++14, etc.). For various reasons, Chromium does not immediately |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 13 | allow new features on the publication of such a standard. Instead, once |
Hong Xu | 68ba51a0 | 2022-04-27 22:21:35 | [diff] [blame] | 14 | Chromium supports the toolchain to a certain extent (e.g., build support is |
| 15 | ready), a standard is declared "_initially supported_", with new |
| 16 | language/library features banned pending discussion but not yet allowed. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 17 | |
| 18 | You can propose changing the status of a feature by sending an email to |
| 19 | [[email protected]](https://groups.google.com/a/chromium.org/forum/#!forum/cxx). |
| 20 | Include a short blurb on what the feature is and why you think it should or |
| 21 | should not be allowed, along with links to any relevant previous discussion. If |
| 22 | the list arrives at some consensus, send a codereview to change this file |
| 23 | accordingly, linking to your discussion thread. |
| 24 | |
| 25 | If an item remains on the TBD list two years after initial support is added, |
| 26 | style arbiters should explicitly move it to an appropriate allowlist or |
| 27 | blocklist, allowing it if there are no obvious reasons to ban. |
| 28 | |
| 29 | The current status of existing standards and Abseil features is: |
| 30 | |
| 31 | * **C++11:** _Default allowed; see banned features below_ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 32 | * **C++14:** _Default allowed_ |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 33 | * **C++17:** Initially supported December 23, 2021; see allowed/banned/TBD |
| 34 | features below |
Arthur Sonzogni | d8517c9 | 2023-03-03 09:41:45 | [diff] [blame^] | 35 | * **C++20:** _Not yet supported in Chromium_, with the exception of |
| 36 | [designated initializers](https://google.github.io/styleguide/cppguide.html#Designated_initializers) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 37 | * **C++23:** _Not yet standardized_ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 38 | * **Abseil:** _Default allowed; see banned/TBD features below_ |
| 39 | * absl::AnyInvocable: Initially supported June 20, 2022 |
| 40 | * Log library: Initially supported Aug 31, 2022 |
| 41 | * CRC32C library: Initially supported Dec 5, 2022 |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 42 | |
| 43 | [TOC] |
| 44 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 45 | ## C++11 Banned Language Features {#core-blocklist-11} |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 46 | |
| 47 | The following C++11 language features are not allowed in the Chromium codebase. |
| 48 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 49 | ### Inline Namespaces <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 50 | |
| 51 | ```c++ |
| 52 | inline namespace foo { ... } |
| 53 | ``` |
| 54 | |
| 55 | **Description:** Allows better versioning of namespaces. |
| 56 | |
| 57 | **Documentation:** |
| 58 | [Inline namespaces](https://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces) |
| 59 | |
| 60 | **Notes:** |
| 61 | *** promo |
| 62 | Banned in the |
| 63 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Namespaces). |
| 64 | Unclear how it will work with components. |
| 65 | *** |
| 66 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 67 | ### long long Type <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 68 | |
| 69 | ```c++ |
| 70 | long long var = value; |
| 71 | ``` |
| 72 | |
| 73 | **Description:** An integer of at least 64 bits. |
| 74 | |
| 75 | **Documentation:** |
| 76 | [Fundamental types](https://en.cppreference.com/w/cpp/language/types) |
| 77 | |
| 78 | **Notes:** |
| 79 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 80 | Use a `<stdint.h>` type if you need a 64-bit number. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 81 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk) |
| 82 | *** |
| 83 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 84 | ### User-Defined Literals <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 85 | |
| 86 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 87 | DistanceType var = 12_km; |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 88 | ``` |
| 89 | |
| 90 | **Description:** Allows user-defined literal expressions. |
| 91 | |
| 92 | **Documentation:** |
| 93 | [User-defined literals](https://en.cppreference.com/w/cpp/language/user_literal) |
| 94 | |
| 95 | **Notes:** |
| 96 | *** promo |
| 97 | Banned in the |
| 98 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Operator_Overloading). |
| 99 | *** |
| 100 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 101 | ## C++11 Banned Library Features {#library-blocklist-11} |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 102 | |
| 103 | The following C++11 library features are not allowed in the Chromium codebase. |
| 104 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 105 | ### <cfenv>, <fenv.h> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 106 | |
| 107 | ```c++ |
| 108 | #include <cfenv> |
| 109 | #include <fenv.h> |
| 110 | ``` |
| 111 | |
| 112 | **Description:** Provides floating point status flags and control modes for |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 113 | C-compatible code. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 114 | |
| 115 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 116 | [Standard library header `<cfenv>`](https://en.cppreference.com/w/cpp/header/cfenv) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 117 | |
| 118 | **Notes:** |
| 119 | *** promo |
| 120 | Banned by the |
| 121 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 122 | due to concerns about compiler support. |
| 123 | *** |
| 124 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 125 | ### <chrono> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 126 | |
| 127 | ```c++ |
| 128 | #include <chrono> |
| 129 | ``` |
| 130 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 131 | **Description:** A standard date and time library. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 132 | |
| 133 | **Documentation:** |
| 134 | [Date and time utilities](https://en.cppreference.com/w/cpp/chrono) |
| 135 | |
| 136 | **Notes:** |
| 137 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 138 | Overlaps with `base/time`. Keep using the `base/time` classes. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 139 | *** |
| 140 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 141 | ### <exception> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 142 | |
| 143 | ```c++ |
| 144 | #include <exception> |
| 145 | ``` |
| 146 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 147 | **Description:** Exception throwing and handling. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 148 | |
| 149 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 150 | [Standard library header `<exception>`](https://en.cppreference.com/w/cpp/header/exception) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 151 | |
| 152 | **Notes:** |
| 153 | *** promo |
| 154 | Exceptions are banned by the |
| 155 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Exceptions) |
| 156 | and disabled in Chromium compiles. However, the `noexcept` specifier is |
| 157 | explicitly allowed. |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 158 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 159 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg) |
| 160 | *** |
| 161 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 162 | ### <random> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 163 | |
| 164 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 165 | #include <random> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 166 | ``` |
| 167 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 168 | **Description:** Random number generation algorithms and utilities. |
| 169 | |
| 170 | **Documentation:** |
| 171 | [Pseudo-random number generation](https://en.cppreference.com/w/cpp/numeric/random) |
| 172 | |
| 173 | **Notes:** |
| 174 | *** promo |
| 175 | Do not use any random number engines from `<random>`. Instead, use |
| 176 | `base::RandomBitGenerator`. |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 177 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 178 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16Xmw05C-Y0) |
| 179 | *** |
| 180 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 181 | ### <ratio> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 182 | |
| 183 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 184 | #include <ratio> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 185 | ``` |
| 186 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 187 | **Description:** Provides compile-time rational numbers. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 188 | |
| 189 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 190 | [`std::ratio`](https://en.cppreference.com/w/cpp/numeric/ratio/ratio) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 191 | |
| 192 | **Notes:** |
| 193 | *** promo |
| 194 | Banned by the |
| 195 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 196 | due to concerns that this is tied to a more template-heavy interface style. |
| 197 | *** |
| 198 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 199 | ### <regex> <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 200 | |
| 201 | ```c++ |
| 202 | #include <regex> |
| 203 | ``` |
| 204 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 205 | **Description:** A standard regular expressions library. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 206 | |
| 207 | **Documentation:** |
| 208 | [Regular expressions library](https://en.cppreference.com/w/cpp/regex) |
| 209 | |
| 210 | **Notes:** |
| 211 | *** promo |
| 212 | Overlaps with many regular expression libraries in Chromium. When in doubt, use |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 213 | `third_party/re2`. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 214 | *** |
| 215 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 216 | ### std::bind <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 217 | |
| 218 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 219 | auto x = std::bind(function, args, ...); |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 220 | ``` |
| 221 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 222 | **Description:** Declares a function object bound to certain arguments. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 223 | |
| 224 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 225 | [`std::bind`](https://en.cppreference.com/w/cpp/utility/functional/bind) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 226 | |
| 227 | **Notes:** |
| 228 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 229 | Use `base::Bind` instead. Compared to `std::bind`, `base::Bind` helps prevent |
| 230 | lifetime issues by preventing binding of capturing lambdas and by forcing |
| 231 | callers to declare raw pointers as `Unretained`. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 232 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 233 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 234 | *** |
| 235 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 236 | ### std::function <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 237 | |
| 238 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 239 | std::function x = [] { return 10; }; |
| 240 | std::function y = std::bind(foo, args); |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 241 | ``` |
| 242 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 243 | **Description:** Wraps a standard polymorphic function. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 244 | |
| 245 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 246 | [`std::function`](https://en.cppreference.com/w/cpp/utility/functional/function) |
| 247 | |
| 248 | **Notes:** |
| 249 | *** promo |
| 250 | Use `base::{Once,Repeating}Callback` instead. Compared to `std::function`, |
| 251 | `base::{Once,Repeating}Callback` directly supports Chromium's refcounting |
| 252 | classes and weak pointers and deals with additional thread safety concerns. |
| 253 | |
| 254 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
| 255 | *** |
| 256 | |
| 257 | ### std::shared_ptr <sup>[banned]</sup> |
| 258 | |
| 259 | ```c++ |
| 260 | std::shared_ptr<int> x = std::make_shared<int>(10); |
| 261 | ``` |
| 262 | |
| 263 | **Description:** Allows shared ownership of a pointer through reference counts. |
| 264 | |
| 265 | **Documentation:** |
| 266 | [`std::shared_ptr`](https://en.cppreference.com/w/cpp/memory/shared_ptr) |
| 267 | |
| 268 | **Notes:** |
| 269 | *** promo |
| 270 | Unlike `base::RefCounted`, uses extrinsic rather than intrinsic reference |
| 271 | counting. Could plausibly be used in Chromium, but would require significant |
| 272 | migration. |
| 273 | |
| 274 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers), |
| 275 | [Discussion Thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/aT2wsBLKvzI) |
| 276 | *** |
| 277 | |
| 278 | ### std::{sto{i,l,ul,ll,ull,f,d,ld},to_string} <sup>[banned]</sup> |
| 279 | |
| 280 | ```c++ |
| 281 | int x = std::stoi("10"); |
| 282 | ``` |
| 283 | |
| 284 | **Description:** Converts strings to/from numbers. |
| 285 | |
| 286 | **Documentation:** |
| 287 | [`std::stoi`, `std::stol`, `std::stoll`](https://en.cppreference.com/w/cpp/string/basic_string/stol), |
| 288 | [`std::stoul`, `std::stoull`](https://en.cppreference.com/w/cpp/string/basic_string/stoul), |
| 289 | [`std::stof`, `std::stod`, `std::stold`](https://en.cppreference.com/w/cpp/string/basic_string/stof), |
| 290 | [`std::to_string`](https://en.cppreference.com/w/cpp/string/basic_string/to_string) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 291 | |
| 292 | **Notes:** |
| 293 | *** promo |
| 294 | The string-to-number conversions rely on exceptions to communicate failure, |
| 295 | while the number-to-string conversions have performance concerns and depend on |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 296 | the locale. Use `base/strings/string_number_conversions.h` instead. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 297 | *** |
| 298 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 299 | ### std::weak_ptr <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 300 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 301 | ```c++ |
| 302 | std::weak_ptr<int> x = my_shared_x; |
| 303 | ``` |
| 304 | |
| 305 | **Description:** Allows a weak reference to a `std::shared_ptr`. |
| 306 | |
| 307 | **Documentation:** |
| 308 | [`std::weak_ptr`](https://en.cppreference.com/w/cpp/memory/weak_ptr) |
| 309 | |
| 310 | **Notes:** |
| 311 | *** promo |
| 312 | Banned because `std::shared_ptr` is banned. Use `base::WeakPtr` instead. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 313 | *** |
| 314 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 315 | ### Thread Support Library <sup>[banned]</sup> |
| 316 | |
| 317 | ```c++ |
| 318 | #include <barrier> // C++20 |
| 319 | #include <condition_variable> |
| 320 | #include <future> |
| 321 | #include <latch> // C++20 |
| 322 | #include <mutex> |
| 323 | #include <semaphore> // C++20 |
| 324 | #include <stop_token> // C++20 |
| 325 | #include <thread> |
| 326 | ``` |
| 327 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 328 | **Description:** Provides a standard multithreading library using `std::thread` |
| 329 | and associates |
| 330 | |
| 331 | **Documentation:** |
| 332 | [Thread support library](https://en.cppreference.com/w/cpp/thread) |
| 333 | |
| 334 | **Notes:** |
| 335 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 336 | Overlaps with many classes in `base/synchronization`. `base::Thread` is tightly |
| 337 | coupled to `base::MessageLoop` which would make it hard to replace. We should |
| 338 | investigate using standard mutexes, or unique_lock, etc. to replace our |
| 339 | locking/synchronization classes. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 340 | *** |
| 341 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 342 | ## C++17 Allowed Language Features {#core-allowlist-17} |
| 343 | |
| 344 | The following C++17 language features are allowed in the Chromium codebase. |
| 345 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 346 | ### Class Template Argument Deduction (CTAD) <sup>[allowed]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 347 | |
| 348 | ```c++ |
| 349 | template <typename T> |
| 350 | struct MyContainer { |
| 351 | MyContainer(T val) : val{val} {} |
| 352 | // ... |
| 353 | }; |
| 354 | MyContainer c1(1); // Type deduced to be `int`. |
| 355 | ``` |
| 356 | |
| 357 | **Description:** Automatic template argument deduction much like how it's done |
| 358 | for functions, but now including class constructors. |
| 359 | |
| 360 | **Documentation:** |
| 361 | [Class template argument deduction](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction) |
| 362 | |
| 363 | **Notes:** |
| 364 | *** promo |
| 365 | Usage is governed by the |
| 366 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#CTAD). |
| 367 | *** |
| 368 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 369 | ### constexpr if <sup>[allowed]</sup> |
Daniel Cheng | 7919c8d | 2022-07-08 01:36:22 | [diff] [blame] | 370 | |
| 371 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 372 | if constexpr (cond) { ... |
Daniel Cheng | 7919c8d | 2022-07-08 01:36:22 | [diff] [blame] | 373 | ``` |
| 374 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 375 | **Description:** Write code that is instantiated depending on a compile-time |
| 376 | condition. |
Daniel Cheng | 7919c8d | 2022-07-08 01:36:22 | [diff] [blame] | 377 | |
| 378 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 379 | [`if` statement](https://en.cppreference.com/w/cpp/language/if) |
Daniel Cheng | 7919c8d | 2022-07-08 01:36:22 | [diff] [blame] | 380 | |
| 381 | **Notes:** |
| 382 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 383 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/op2ePZnjP0w) |
Daniel Cheng | 7919c8d | 2022-07-08 01:36:22 | [diff] [blame] | 384 | *** |
| 385 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 386 | ### constexpr lambda <sup>[allowed]</sup> |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 387 | |
| 388 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 389 | auto identity = [](int n) constexpr { return n; }; |
| 390 | static_assert(identity(123) == 123); |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 391 | ``` |
| 392 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 393 | **Description:** Compile-time lambdas using constexpr. |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 394 | |
| 395 | **Documentation:** |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 396 | [Lambda expressions](https://en.cppreference.com/w/cpp/language/lambda) |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 397 | |
| 398 | **Notes:** |
| 399 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 400 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 401 | *** |
| 402 | |
| 403 | ### Declaring non-type template parameters with auto <sup>[allowed]</sup> |
| 404 | |
| 405 | ```c++ |
| 406 | template <auto... seq> |
| 407 | struct my_integer_sequence { |
| 408 | // ... |
| 409 | }; |
| 410 | auto seq = my_integer_sequence<0, 1, 2>(); // Type deduced to be `int`. |
| 411 | ``` |
| 412 | |
| 413 | **Description:** Following the deduction rules of `auto`, while respecting the |
| 414 | non-type template parameter list of allowable types, template arguments can be |
| 415 | deduced from the types of its arguments. |
| 416 | |
| 417 | **Documentation:** |
| 418 | [Template parameters](https://en.cppreference.com/w/cpp/language/template_parameters) |
| 419 | |
| 420 | **Notes:** |
| 421 | *** promo |
| 422 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 423 | *** |
| 424 | |
Roland Bock | f5242fb | 2022-01-05 17:54:38 | [diff] [blame] | 425 | ### fallthrough attribute <sup>[allowed]</sup> |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 426 | |
| 427 | ```c++ |
| 428 | case 1: |
| 429 | DoSomething(); |
| 430 | [[fallthrough]]; |
| 431 | case 2: |
| 432 | break; |
| 433 | ``` |
| 434 | |
| 435 | **Description:** |
| 436 | The `[[fallthrough]]` attribute can be used in switch statements to indicate |
| 437 | when intentionally falling through to the next case. |
| 438 | |
| 439 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 440 | [C++ attribute: `fallthrough`](https://en.cppreference.com/w/cpp/language/attributes/fallthrough) |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 441 | |
| 442 | **Notes:** |
| 443 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 444 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JrvyFd243QI) |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 445 | *** |
| 446 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 447 | ### Fold expressions <sup>[allowed]</sup> |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 448 | |
| 449 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 450 | template <typename... Args> |
| 451 | auto sum(Args... args) { |
| 452 | return (... + args); |
| 453 | } |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 454 | ``` |
| 455 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 456 | **Description:** A fold expression performs a fold of a template parameter pack |
| 457 | over a binary operator. |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 458 | |
| 459 | **Documentation:** |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 460 | [Fold expression](https://en.cppreference.com/w/cpp/language/fold) |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 461 | |
| 462 | **Notes:** |
| 463 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 464 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/4DTm3idXz0w) |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 465 | *** |
| 466 | |
Avi Drissman | 37b7d51 | 2022-04-01 22:01:40 | [diff] [blame] | 467 | ### Inline variables <sup>[allowed]</sup> |
Bruce Dawson | bb51b003 | 2022-01-14 19:24:22 | [diff] [blame] | 468 | |
| 469 | ```c++ |
| 470 | struct S { |
| 471 | static constexpr int kZero = 0; // constexpr implies inline here. |
| 472 | }; |
| 473 | |
Victor Vianna | 7f2773f | 2022-02-08 14:44:56 | [diff] [blame] | 474 | inline constexpr int kOne = 1; // Explicit inline needed here. |
Bruce Dawson | bb51b003 | 2022-01-14 19:24:22 | [diff] [blame] | 475 | ``` |
| 476 | |
| 477 | **Description:** The `inline` specifier can be applied to variables as well as |
| 478 | to functions. A variable declared inline has the same semantics as a function |
| 479 | declared inline. It can also be used to declare and define a static member |
| 480 | variable, such that it does not need to be initialized in the source file. |
| 481 | |
| 482 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 483 | [`inline` specifier](https://en.cppreference.com/w/cpp/language/inline) |
Bruce Dawson | bb51b003 | 2022-01-14 19:24:22 | [diff] [blame] | 484 | |
| 485 | **Notes:** |
| 486 | *** promo |
| 487 | Inline variables in anonymous namespaces in header files will still get one copy |
| 488 | per translation unit, so they must be outside of an anonymous namespace to be |
| 489 | effective. |
| 490 | |
| 491 | Mutable inline variables and taking the address of inline variables are banned |
| 492 | since these will break the component build. |
| 493 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 494 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/hmyGFD80ocE) |
| 495 | *** |
| 496 | |
| 497 | ### __has_include <sup>[allowed]</sup> |
| 498 | |
| 499 | ```c++ |
| 500 | #if __has_include(<optional>) ... |
| 501 | ``` |
| 502 | |
| 503 | **Description:** Checks whether a file is available for inclusion, i.e. the file |
| 504 | exists. |
| 505 | |
| 506 | **Documentation:** |
| 507 | [Source file inclusion](https://en.cppreference.com/w/cpp/preprocessor/include) |
| 508 | |
| 509 | **Notes:** |
| 510 | *** promo |
| 511 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 512 | *** |
| 513 | |
| 514 | ### Lambda capture this by value <sup>[allowed]</sup> |
| 515 | |
| 516 | ```c++ |
| 517 | const auto l = [*this] { return member_; } |
| 518 | ``` |
| 519 | |
| 520 | **Description:** `*this` captures the current object by copy, while `this` |
| 521 | continues to capture by reference. |
| 522 | |
| 523 | **Documentation:** |
| 524 | [Lambda capture](https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture) |
| 525 | |
| 526 | **Notes:** |
| 527 | *** promo |
| 528 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 529 | *** |
| 530 | |
| 531 | ### maybe_unused attribute <sup>[allowed]</sup> |
| 532 | |
| 533 | ```c++ |
| 534 | struct [[maybe_unused]] MyUnusedThing; |
| 535 | [[maybe_unused]] int x; |
| 536 | ``` |
| 537 | |
| 538 | **Description:** |
| 539 | The `[[maybe_unused]]` attribute can be used to indicate that individual |
| 540 | variables, functions, or fields of a class/struct/enum can be left unused. |
| 541 | |
| 542 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 543 | [C++ attribute: `maybe_unused`](https://en.cppreference.com/w/cpp/language/attributes/maybe_unused) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 544 | |
| 545 | **Notes:** |
| 546 | *** promo |
| 547 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/jPLfU5eRg8M/) |
| 548 | *** |
| 549 | |
| 550 | ### Nested namespaces <sup>[allowed]</sup> |
| 551 | |
| 552 | ```c++ |
| 553 | namespace A::B::C { ... |
| 554 | ``` |
| 555 | |
| 556 | **Description:** Using the namespace resolution operator to create nested |
| 557 | namespace definitions. |
| 558 | |
| 559 | **Documentation:** |
| 560 | [Namespaces](https://en.cppreference.com/w/cpp/language/namespace) |
| 561 | |
| 562 | **Notes:** |
| 563 | *** promo |
| 564 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/gLdR3apDSmg/) |
| 565 | *** |
| 566 | |
| 567 | ### nodiscard attribute <sup>[allowed]</sup> |
| 568 | |
| 569 | ```c++ |
| 570 | struct [[nodiscard]] ErrorOrValue; |
| 571 | [[nodiscard]] bool DoSomething(); |
| 572 | ``` |
| 573 | |
| 574 | **Description:** |
| 575 | The `[[nodiscard]]` attribute can be used to indicate that |
| 576 | |
| 577 | - the return value of a function should not be ignored |
| 578 | - values of annotated classes/structs/enums returned from functions should not |
| 579 | be ignored |
| 580 | |
| 581 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 582 | [C++ attribute: `nodiscard`](https://en.cppreference.com/w/cpp/language/attributes/nodiscard) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 583 | |
| 584 | **Notes:** |
| 585 | *** promo |
| 586 | This replaces the previous `WARN_UNUSED_RESULT` macro, which was a wrapper |
| 587 | around the compiler-specific `__attribute__((warn_unused_result))`. |
| 588 | |
| 589 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/nH7Ar8pZ1Dw) |
| 590 | *** |
| 591 | |
| 592 | ### Selection statements with initializer <sup>[allowed]</sup> |
| 593 | |
| 594 | ```c++ |
| 595 | if (int a = Func(); a < 3) { ... |
| 596 | switch (int a = Func(); a) { ... |
| 597 | ``` |
| 598 | |
| 599 | **Description:** New versions of the if and switch statements which simplify |
| 600 | common code patterns and help users keep scopes tight. |
| 601 | |
| 602 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 603 | [`if` statement](https://en.cppreference.com/w/cpp/language/if), |
| 604 | [`switch` statement](https://en.cppreference.com/w/cpp/language/switch) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 605 | |
| 606 | **Notes:** |
| 607 | *** promo |
| 608 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/4GP43nftePE) |
| 609 | *** |
| 610 | |
| 611 | ### Structured bindings <sup>[allowed]</sup> |
| 612 | |
| 613 | ```c++ |
| 614 | const auto [x, y] = FuncReturningStdPair(); |
| 615 | ``` |
| 616 | |
| 617 | **Description:** Allows writing `auto [x, y, z] = expr;` where the type of |
| 618 | `expr` is a tuple-like object, whose elements are bound to the variables `x`, |
| 619 | `y`, and `z` (which this construct declares). Tuple-like objects include |
| 620 | `std::tuple`, `std::pair`, `std::array`, and aggregate structures. |
| 621 | |
| 622 | **Documentation:** |
| 623 | [Structured binding declaration](https://en.cppreference.com/w/cpp/language/structured_binding) |
| 624 | [Explanation of structured binding types](https://jguegant.github.io/blogs/tech/structured-bindings.html) |
| 625 | |
| 626 | **Notes:** |
| 627 | *** promo |
| 628 | In C++17, structured bindings don't work with lambda captures. |
| 629 | [C++20 will allow capturing structured bindings by value](https://wg21.link/p1091r3). |
| 630 | |
| 631 | This feature forces omitting type names. Its use should follow |
| 632 | [the guidance around `auto` in Google C++ Style guide](https://google.github.io/styleguide/cppguide.html#Type_deduction). |
| 633 | |
| 634 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ExfSorNLNf4) |
| 635 | *** |
| 636 | |
| 637 | ### using declaration for attributes <sup>[allowed]</sup> |
| 638 | |
| 639 | ```c++ |
| 640 | [[using CC: opt(1), debug]] // same as [[CC:opt(1), CC::debug]] |
| 641 | ``` |
| 642 | |
| 643 | **Description:** Specifies a common namespace for a list of attributes. |
| 644 | |
| 645 | **Documentation:** |
| 646 | [Attribute specifier sequence](https://en.cppreference.com/w/cpp/language/attributes) |
| 647 | |
| 648 | **Notes:** |
| 649 | *** promo |
| 650 | See similar attribute macros in base/compiler_specific.h. |
Bruce Dawson | bb51b003 | 2022-01-14 19:24:22 | [diff] [blame] | 651 | *** |
| 652 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 653 | ## C++17 Allowed Library Features {#library-allowlist-17} |
| 654 | |
| 655 | The following C++17 language features are allowed in the Chromium codebase. |
| 656 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 657 | ### 3D std::hypot <sup>[allowed]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 658 | |
| 659 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 660 | double dist = std::hypot(1.0, 2.5, 3.7); |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 661 | ``` |
| 662 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 663 | **Description:** Computes the distance from the origin in 3D space. |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 664 | |
| 665 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 666 | [`std::hypot`](https://en.cppreference.com/w/cpp/numeric/math/hypot) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 667 | |
| 668 | **Notes:** |
| 669 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 670 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 671 | *** |
| 672 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 673 | ### Searchers <sup>[allowed]</sup> |
Daniel Cheng | a371b4c | 2022-01-14 18:24:27 | [diff] [blame] | 674 | |
| 675 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 676 | auto it = std::search(haystack.begin(), haystack.end(), |
| 677 | std::boyer_moore_searcher(needle.begin(), needle.end())); |
Daniel Cheng | a371b4c | 2022-01-14 18:24:27 | [diff] [blame] | 678 | ``` |
| 679 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 680 | **Description:** Alternate string searching algorithms. |
Daniel Cheng | a371b4c | 2022-01-14 18:24:27 | [diff] [blame] | 681 | |
| 682 | **Documentation:** |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 683 | [Searchers](https://en.cppreference.com/w/cpp/utility/functional#Searchers) |
Daniel Cheng | a371b4c | 2022-01-14 18:24:27 | [diff] [blame] | 684 | |
| 685 | **Notes:** |
| 686 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 687 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
Daniel Cheng | a371b4c | 2022-01-14 18:24:27 | [diff] [blame] | 688 | *** |
| 689 | |
Peter Kasting | d51bed7 | 2022-09-09 19:40:00 | [diff] [blame] | 690 | ### std::apply <sup>[allowed]</sup> |
| 691 | |
| 692 | ```c++ |
| 693 | static_assert(std::apply(std::plus<>(), std::make_tuple(1, 2)) == 3); |
| 694 | ``` |
| 695 | |
| 696 | **Description:** Invokes a `Callable` object with a tuple of arguments. |
| 697 | |
| 698 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 699 | [`std::apply`](https://en.cppreference.com/w/cpp/utility/apply) |
Peter Kasting | d51bed7 | 2022-09-09 19:40:00 | [diff] [blame] | 700 | |
| 701 | **Notes:** |
| 702 | *** promo |
| 703 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/cNZm_g39fyM) |
| 704 | *** |
| 705 | |
Lei Zhang | aaf6fc2 | 2022-10-06 23:12:42 | [diff] [blame] | 706 | ### std::as_const <sup>[allowed]</sup> |
| 707 | |
| 708 | ```c++ |
| 709 | auto&& const_ref = std::as_const(mutable_obj); |
| 710 | ``` |
| 711 | |
| 712 | **Description:** Forms reference to const T. |
| 713 | |
| 714 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 715 | [`std::as_const`](https://en.cppreference.com/w/cpp/utility/as_const) |
Lei Zhang | aaf6fc2 | 2022-10-06 23:12:42 | [diff] [blame] | 716 | |
| 717 | **Notes:** |
| 718 | *** promo |
| 719 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/5Uo4iJK6Mf4) |
| 720 | *** |
| 721 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 722 | ### std::atomic<T>::is_always_lock_free <sup>[allowed]</sup> |
Daniel Cheng | 4ddc920 | 2022-02-24 20:19:26 | [diff] [blame] | 723 | |
| 724 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 725 | template <typename T> |
| 726 | struct is_lock_free_impl |
| 727 | : std::integral_constant<bool, std::atomic<T>::is_always_lock_free> {}; |
Daniel Cheng | 4ddc920 | 2022-02-24 20:19:26 | [diff] [blame] | 728 | ``` |
| 729 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 730 | **Description:** True when the given atomic type is always lock-free. |
Daniel Cheng | 4ddc920 | 2022-02-24 20:19:26 | [diff] [blame] | 731 | |
| 732 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 733 | [`std::atomic<T>::is_always_lock_free`](https://en.cppreference.com/w/cpp/atomic/atomic/is_always_lock_free) |
Daniel Cheng | 4ddc920 | 2022-02-24 20:19:26 | [diff] [blame] | 734 | |
| 735 | **Notes:** |
| 736 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 737 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
Avi Drissman | 67c3b1e | 2022-04-27 20:42:49 | [diff] [blame] | 738 | *** |
| 739 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 740 | ### std::{{con,dis}junction,negation} <sup>[allowed]</sup> |
Avi Drissman | c109efd | 2022-04-27 22:03:35 | [diff] [blame] | 741 | |
| 742 | ```c++ |
| 743 | template<typename T, typename... Ts> |
| 744 | std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>> |
| 745 | func(T, Ts...) { ... |
| 746 | ``` |
| 747 | |
| 748 | **Description:** Performs logical operations on type traits. |
| 749 | |
| 750 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 751 | [`std::conjunction`](https://en.cppreference.com/w/cpp/types/conjunction), |
| 752 | [`std::disjunction`](https://en.cppreference.com/w/cpp/types/disjunction), |
| 753 | [`std::negation`](https://en.cppreference.com/w/cpp/types/negation) |
Avi Drissman | c109efd | 2022-04-27 22:03:35 | [diff] [blame] | 754 | |
| 755 | **Notes:** |
| 756 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 757 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/YhlF_sTDSc0) |
Avi Drissman | c109efd | 2022-04-27 22:03:35 | [diff] [blame] | 758 | *** |
| 759 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 760 | ### std::exclusive_scan <sup>[allowed]</sup> |
| 761 | |
| 762 | ```c++ |
| 763 | std::exclusive_scan(data.begin(), data.end(), output.begin()); |
| 764 | ``` |
| 765 | |
| 766 | **Description:** Like `std::inclusive_scan` but omits the current element from |
| 767 | the written output at each step; that is, results are "one value behind" those |
| 768 | of `std::inclusive_scan`. |
| 769 | |
| 770 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 771 | [`std::exclusive_scan`](https://en.cppreference.com/w/cpp/algorithm/exclusive_scan) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 772 | |
| 773 | **Notes:** |
| 774 | *** promo |
| 775 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 776 | *** |
| 777 | |
| 778 | ### std::gcd <sup>[allowed]</sup> |
| 779 | |
| 780 | ```c++ |
| 781 | static_assert(std::gcd(12, 18) == 6); |
| 782 | ``` |
| 783 | |
| 784 | **Description:** Computes the greatest common divisor of its arguments. |
| 785 | |
| 786 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 787 | [`std::gcd`](https://en.cppreference.com/w/cpp/numeric/gcd) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 788 | |
| 789 | **Notes:** |
| 790 | *** promo |
| 791 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 792 | *** |
| 793 | |
| 794 | ### std::has_unique_object_representations <sup>[allowed]</sup> |
| 795 | |
| 796 | ```c++ |
| 797 | std::has_unique_object_representations_v<foo> |
| 798 | ``` |
| 799 | |
| 800 | **Description:** Checks wither the given type is trivially copyable and any two |
| 801 | objects with the same value have the same object representation. |
| 802 | |
| 803 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 804 | [`std::has_unique_object_representations`](https://en.cppreference.com/w/cpp/types/has_unique_object_representations) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 805 | |
| 806 | **Notes:** |
| 807 | *** promo |
| 808 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 809 | *** |
| 810 | |
| 811 | ### std::inclusive_scan <sup>[allowed]</sup> |
| 812 | |
| 813 | ```c++ |
| 814 | std::inclusive_scan(data.begin(), data.end(), output.begin()); |
| 815 | ``` |
| 816 | |
| 817 | **Description:** Like `std::accumulate` but writes the result at each step into |
| 818 | the output range. |
| 819 | |
| 820 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 821 | [`std::inclusive_scan`](https://en.cppreference.com/w/cpp/algorithm/inclusive_scan) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 822 | |
| 823 | **Notes:** |
| 824 | *** promo |
| 825 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 826 | *** |
| 827 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 828 | ### std::invoke <sup>[allowed]</sup> |
| 829 | |
| 830 | ```c++ |
| 831 | static_assert(std::invoke(std::plus<>(), 1, 2) == 3); |
| 832 | ``` |
| 833 | |
| 834 | **Description:** Invokes a callable object with parameters. A callable object is |
| 835 | e.g. a function, function pointer, functor (that is, an object that provides |
| 836 | `operator()`), lambda, etc. |
| 837 | |
| 838 | **Documentation:** |
| 839 | [`std::invoke`](https://en.cppreference.com/w/cpp/utility/functional/invoke) |
| 840 | |
| 841 | **Notes:** |
| 842 | *** promo |
| 843 | [Migration bug](https://crbug.com/1412520) |
| 844 | *** |
| 845 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 846 | ### std::is_aggregate <sup>[allowed]</sup> |
| 847 | |
| 848 | ```c++ |
| 849 | if constexpr(std::is_aggregate_v<T>) { ... |
| 850 | ``` |
| 851 | |
| 852 | **Description:** Checks wither the given type is an aggregate type. |
| 853 | |
| 854 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 855 | [`std::is_aggregate`](https://en.cppreference.com/w/cpp/types/is_aggregate) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 856 | |
| 857 | **Notes:** |
| 858 | *** promo |
| 859 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 860 | *** |
| 861 | |
| 862 | ### std::is_invocable <sup>[allowed]</sup> |
| 863 | |
| 864 | ```c++ |
| 865 | std::is_invocable_v<Fn, 1, "Hello"> |
| 866 | ``` |
| 867 | |
| 868 | **Description:** Checks whether a function may be invoked with the given |
| 869 | argument types. The `_r` variant also evaluates whether the result is |
| 870 | convertible to a given type. |
| 871 | |
| 872 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 873 | [`std::is_invocable`](https://en.cppreference.com/w/cpp/types/is_invocable) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 874 | |
| 875 | **Notes:** |
| 876 | *** promo |
| 877 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/YhlF_sTDSc0) |
| 878 | *** |
| 879 | |
| 880 | ### std::is_swappable <sup>[allowed]</sup> |
| 881 | |
| 882 | ```c++ |
| 883 | std::is_swappable<T> |
| 884 | std::is_swappable_with_v<T, U> |
| 885 | ``` |
| 886 | |
| 887 | **Description:** Checks whether classes may be swapped. |
| 888 | |
| 889 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 890 | [`std::is_swappable`](https://en.cppreference.com/w/cpp/types/is_swappable) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 891 | |
| 892 | **Notes:** |
| 893 | *** promo |
| 894 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 895 | *** |
| 896 | |
| 897 | ### std::launder <sup>[allowed]</sup> |
| 898 | |
| 899 | ```c++ |
| 900 | struct Y { int z; }; |
| 901 | alignas(Y) std::byte s[sizeof(Y)]; |
| 902 | Y* q = new(&s) Y{2}; |
| 903 | const int h = std::launder(reinterpret_cast<Y*>(&s))->z; |
| 904 | ``` |
| 905 | |
| 906 | **Description:** When used to wrap a pointer, makes it valid to access the |
| 907 | resulting object in cases it otherwise wouldn't have been, in a very limited set |
| 908 | of circumstances. |
| 909 | |
| 910 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 911 | [`std::launder`](https://en.cppreference.com/w/cpp/utility/launder) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 912 | |
| 913 | **Notes:** |
| 914 | *** promo |
| 915 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 916 | *** |
| 917 | |
| 918 | ### std::lcm <sup>[allowed]</sup> |
| 919 | |
| 920 | ```c++ |
| 921 | static_assert(std::lcm(12, 18) == 36); |
| 922 | ``` |
| 923 | |
| 924 | **Description:** Computes the least common multiple of its arguments. |
| 925 | |
| 926 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 927 | [`std::lcm`](https://en.cppreference.com/w/cpp/numeric/lcm) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 928 | |
| 929 | **Notes:** |
| 930 | *** promo |
| 931 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 932 | *** |
| 933 | |
| 934 | ### std::make_from_tuple <sup>[allowed]</sup> |
| 935 | |
| 936 | ```c++ |
| 937 | // Calls Foo(int, double): |
| 938 | auto foo = std::make_from_tuple<Foo>(std::make_tuple(1, 3.5)); |
| 939 | ``` |
| 940 | |
| 941 | **Description:** Constructs an object from a tuple of arguments. |
| 942 | |
| 943 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 944 | [`std::make_from_tuple`](https://en.cppreference.com/w/cpp/utility/make_from_tuple) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 945 | |
| 946 | **Notes:** |
| 947 | *** promo |
| 948 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 949 | *** |
| 950 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 951 | ### std::map::{extract,merge} <sup>[allowed]</sup> |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 952 | |
| 953 | ```c++ |
| 954 | std::map<...>::extract |
| 955 | std::map<...>::merge |
| 956 | std::set<...>::extract |
| 957 | std::set<...>::merge |
| 958 | ``` |
| 959 | |
| 960 | **Description:** Moving nodes and merging containers without the overhead of |
| 961 | expensive copies, moves, or heap allocations/deallocations. |
| 962 | |
| 963 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 964 | [`std::map::extract`](https://en.cppreference.com/w/cpp/container/map/extract), |
| 965 | [`std::map::merge`](https://en.cppreference.com/w/cpp/container/map/merge) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 966 | |
| 967 | **Notes:** |
| 968 | *** promo |
| 969 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 970 | *** |
| 971 | |
| 972 | ### std::map::insert_or_assign <sup>[allowed]</sup> |
| 973 | |
| 974 | ```c++ |
| 975 | std::map<std::string, std::string> m; |
| 976 | m.insert_or_assign("c", "cherry"); |
| 977 | m.insert_or_assign("c", "clementine"); |
| 978 | ``` |
| 979 | |
| 980 | **Description:** Like `operator[]`, but returns more information and does not |
| 981 | require default-constructibility of the mapped type. |
| 982 | |
| 983 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 984 | [`std::map::insert_or_assign`](https://en.cppreference.com/w/cpp/container/map/insert_or_assign) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 985 | |
| 986 | **Notes:** |
| 987 | *** promo |
| 988 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/Uv2tUfIwUfQ) |
| 989 | *** |
| 990 | |
| 991 | ### std::map::try_emplace <sup>[allowed]</sup> |
| 992 | |
| 993 | ```c++ |
| 994 | std::map<std::string, std::string> m; |
| 995 | m.try_emplace("c", 10, 'c'); |
| 996 | m.try_emplace("c", "Won't be inserted"); |
| 997 | ``` |
| 998 | |
| 999 | **Description:** Like `emplace`, but does not move from rvalue arguments if the |
| 1000 | insertion does not happen. |
| 1001 | |
| 1002 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1003 | [`std::map::try_emplace`](https://en.cppreference.com/w/cpp/container/map/try_emplace), |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1004 | |
| 1005 | **Notes:** |
| 1006 | *** promo |
| 1007 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/Uv2tUfIwUfQ) |
| 1008 | *** |
| 1009 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1010 | ### std::not_fn <sup>[allowed]</sup> |
| 1011 | |
| 1012 | ```c++ |
| 1013 | auto nonwhite = std::find_if(str.begin(), str.end(), std::not_fn(IsWhitespace)); |
| 1014 | ``` |
| 1015 | |
| 1016 | **Description:** Creates a forwarding call wrapper that returns the negation of |
| 1017 | the callable object it holds. |
| 1018 | |
| 1019 | **Documentation:** |
| 1020 | [`std::not_fn`](https://en.cppreference.com/w/cpp/utility/functional/not_fn) |
| 1021 | |
| 1022 | **Notes:** |
| 1023 | *** promo |
| 1024 | [Migration bug](https://crbug.com/1412529) |
| 1025 | *** |
| 1026 | |
| 1027 | ### std::{size,empty,data} <sup>[allowed]</sup> |
| 1028 | |
| 1029 | ```c++ |
| 1030 | char buffer[260]; |
| 1031 | memcpy(std::data(buffer), source_str.data(), std::size(buffer)); |
| 1032 | |
| 1033 | if (!std::empty(container)) { ... } |
| 1034 | ``` |
| 1035 | |
| 1036 | **Description:** Non-member versions of what are often member functions on STL |
| 1037 | containers. Primarily useful when: |
| 1038 | - using `std::size()` as a replacement for the old `arraysize()` macro. |
| 1039 | - writing code that needs to generically operate across things like |
| 1040 | `std::vector` and `std::list` (which provide `size()`, `empty()`, and `data() |
| 1041 | member functions), `std::array` and `std::initialize_list` (which only provide |
| 1042 | a subset of the aforementioned member functions), and regular arrays (which |
| 1043 | have no member functions at all). |
| 1044 | |
| 1045 | **Documentation:** |
| 1046 | [`std::size`](https://en.cppreference.com/w/cpp/iterator/size), |
| 1047 | [`std::empty`](https://en.cppreference.com/w/cpp/iterator/empty), |
| 1048 | [`std::data`](https://en.cppreference.com/w/cpp/iterator/data) |
| 1049 | |
| 1050 | **Notes:** |
| 1051 | *** promo |
| 1052 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/58qlA3zk5ZI) |
| 1053 | |
| 1054 | Prefer range-based for loops over `std::size()`: range-based for loops work even |
| 1055 | for regular arrays. |
| 1056 | *** |
| 1057 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1058 | ### Type trait variable templates <sup>[allowed]</sup> |
| 1059 | |
| 1060 | ```c++ |
| 1061 | bool b = std::is_same_v<int, std::int32_t>; |
| 1062 | ``` |
| 1063 | |
| 1064 | **Description:** Syntactic sugar to provide convenient access to `::value` |
| 1065 | members by simply adding `_v`. |
| 1066 | |
| 1067 | **Documentation:** |
| 1068 | [Type support](https://en.cppreference.com/w/cpp/types) |
| 1069 | |
| 1070 | **Notes:** |
| 1071 | *** promo |
| 1072 | [Discussion thread](Non://groups.google.com/a/chromium.org/g/cxx/c/KEa-0AOGRNY) |
| 1073 | *** |
| 1074 | |
| 1075 | ### Uninitialized memory algorithms <sup>[allowed]</sup> |
| 1076 | |
| 1077 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1078 | std::destroy(ptr, ptr + 8); |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1079 | std::destroy_at(ptr); |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1080 | std::destroy_n(ptr, 8); |
| 1081 | std::uninitialized_move(src.begin(), src.end(), dest.begin()); |
| 1082 | std::uninitialized_value_construct(std::begin(storage), std::end(storage)); |
| 1083 | ``` |
| 1084 | |
| 1085 | **Description:** Replaces direct constructor and destructor calls when manually |
| 1086 | managing memory. |
| 1087 | |
| 1088 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1089 | [`std::destroy`](https://en.cppreference.com/w/cpp/memory/destroy), |
| 1090 | [`std::destroy_at`](https://en.cppreference.com/w/cpp/memory/destroy_at), |
| 1091 | [`std::destroy_n`](https://en.cppreference.com/w/cpp/memory/destroy_n), |
| 1092 | [`std::uninitialized_move`](https://en.cppreference.com/w/cpp/memory/uninitialized_move), |
| 1093 | [`std::uninitialized_value_construct`](https://en.cppreference.com/w/cpp/memory/uninitialized_value_construct) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1094 | |
| 1095 | **Notes:** |
| 1096 | *** promo |
| 1097 | [Discussion thread](https://groups.google.com/u/1/a/chromium.org/g/cxx/c/jNMsxFTd30M) |
| 1098 | *** |
| 1099 | |
| 1100 | ## C++17 Banned Library Features {#library-blocklist-17} |
| 1101 | |
| 1102 | The following C++17 library features are not allowed in the Chromium codebase. |
| 1103 | |
| 1104 | ### std::aligned_alloc <sup>[banned]</sup> |
| 1105 | |
| 1106 | ```c++ |
| 1107 | int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024)); |
| 1108 | ``` |
| 1109 | |
| 1110 | **Description:** Allocates uninitialized storage with the specified alignment. |
| 1111 | |
| 1112 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1113 | [`std::aligned_alloc`](https://en.cppreference.com/w/cpp/memory/c/aligned_alloc) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1114 | |
| 1115 | **Notes:** |
| 1116 | *** promo |
| 1117 | [Will be allowed soon](https://crbug.com/1412818); for now, use |
| 1118 | `base::AlignedAlloc`. |
| 1119 | *** |
| 1120 | |
| 1121 | ### std::any <sup>[banned]</sup> |
| 1122 | |
| 1123 | ```c++ |
| 1124 | std::any x = 5; |
| 1125 | ``` |
| 1126 | |
| 1127 | **Description:** A type-safe container for single values of any type. |
| 1128 | |
| 1129 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1130 | [`std::any`](https://en.cppreference.com/w/cpp/utility/any) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1131 | |
| 1132 | **Notes:** |
| 1133 | *** promo |
| 1134 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/00cpZ07nye4) |
| 1135 | |
| 1136 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 1137 | build ([Bug](https://crbug.com/1096380)). Also see `absl::any`. |
| 1138 | *** |
| 1139 | |
| 1140 | ### std::clamp <sup>[banned]</sup> |
| 1141 | |
| 1142 | ```c++ |
| 1143 | int x = std::clamp(inp, 0, 100); |
| 1144 | ``` |
| 1145 | |
| 1146 | **Description:** Clamps a value between a minimum and a maximum. |
| 1147 | |
| 1148 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1149 | [`std::clamp`](https://en.cppreference.com/w/cpp/algorithm/clamp) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1150 | |
| 1151 | **Notes:** |
| 1152 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1153 | [Will be allowed soon](https://crbug.com/1373621); for now, use `base::clamp`. |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1154 | *** |
| 1155 | |
| 1156 | ### std::filesystem <sup>[banned]</sup> |
| 1157 | |
| 1158 | ```c++ |
| 1159 | #include <filesystem> |
| 1160 | ``` |
| 1161 | |
| 1162 | **Description:** A standard way to manipulate files, directories, and paths in a |
| 1163 | filesystem. |
| 1164 | |
| 1165 | **Documentation:** |
| 1166 | [Filesystem library](https://en.cppreference.com/w/cpp/filesystem) |
| 1167 | |
| 1168 | **Notes:** |
| 1169 | *** promo |
| 1170 | Banned by the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Other_Features). |
| 1171 | *** |
| 1172 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1173 | ### std::hardware_{con,de}structive_interference_size <sup>[banned]</sup> |
Anton Bikineev | c6a02258 | 2022-10-10 19:08:58 | [diff] [blame] | 1174 | |
| 1175 | ```c++ |
| 1176 | struct SharedData { |
| 1177 | ReadOnlyFrequentlyUsed data; |
| 1178 | alignas(std::hardware_destructive_interference_size) std::atomic<size_t> counter; |
| 1179 | }; |
| 1180 | ``` |
| 1181 | |
| 1182 | **Description:** The `std::hardware_destructive_interference_size` constant is |
| 1183 | useful to avoid false sharing (destructive interference) between variables that |
| 1184 | would otherwise occupy the same cacheline. In contrast, |
| 1185 | `std::hardware_constructive_interference_size` is helpful to promote true |
| 1186 | sharing (constructive interference), e.g. to support better locality for |
| 1187 | non-contended data. |
| 1188 | |
| 1189 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1190 | [`std::hardware_destructive_interference_size`](https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size), |
| 1191 | [`std::hardware_constructive_interference_size`](https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size) |
Anton Bikineev | c6a02258 | 2022-10-10 19:08:58 | [diff] [blame] | 1192 | |
| 1193 | **Notes:** |
| 1194 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1195 | Banned for now since these are |
| 1196 | [not supported yet](https://github.com/llvm/llvm-project/issues/60174). Allow |
| 1197 | once supported. |
| 1198 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/cwktrFxxUY4) |
Avi Drissman | 37b7d51 | 2022-04-01 22:01:40 | [diff] [blame] | 1199 | *** |
| 1200 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1201 | ### std::in_place[_type,_index][_t] <sup>[banned]</sup> |
Avi Drissman | bc6545f4 | 2022-05-03 17:47:38 | [diff] [blame] | 1202 | |
| 1203 | ```c++ |
| 1204 | std::optional<std::complex<double>> opt{std::in_place, 0, 1}; |
| 1205 | std::variant<int, float> v{std::in_place_type<int>, 1.4}; |
| 1206 | ``` |
| 1207 | |
| 1208 | **Description:** The `std::in_place` are disambiguation tags for |
| 1209 | `std::optional`, `std::variant`, and `std::any` to indicate that the object |
| 1210 | should be constructed in-place. |
| 1211 | |
| 1212 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1213 | [`std::in_place`](https://en.cppreference.com/w/cpp/utility/in_place) |
Avi Drissman | bc6545f4 | 2022-05-03 17:47:38 | [diff] [blame] | 1214 | |
| 1215 | **Notes:** |
| 1216 | *** promo |
| 1217 | Banned for now because `std::optional`, `std::variant`, and `std::any` are all |
| 1218 | banned for now. Because `absl::optional` and `absl::variant` are used instead, |
| 1219 | and they require `absl::in_place`, use `absl::in_place` for non-Abseil Chromium |
| 1220 | code. See the |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1221 | [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ZspmuJPpv6s). |
Avi Drissman | bc6545f4 | 2022-05-03 17:47:38 | [diff] [blame] | 1222 | *** |
| 1223 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1224 | ### std::optional <sup>[banned]</sup> |
| 1225 | |
| 1226 | ```c++ |
| 1227 | std::optional<std::string> s; |
| 1228 | ``` |
| 1229 | |
| 1230 | **Description:** The class template `std::optional` manages an optional |
| 1231 | contained value, i.e. a value that may or may not be present. A common use case |
| 1232 | for optional is the return value of a function that may fail. |
| 1233 | |
| 1234 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1235 | [`std::optional`](https://en.cppreference.com/w/cpp/utility/optional) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1236 | |
| 1237 | **Notes:** |
| 1238 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1239 | [Will be allowed soon](https://crbug.com/1373619); for now, use |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1240 | `absl::optional`. |
| 1241 | *** |
| 1242 | |
| 1243 | ### std::[u16]string_view <sup>[banned]</sup> |
| 1244 | |
| 1245 | ```c++ |
| 1246 | std::string_view str = "foo"; |
| 1247 | std::u16string_view str16 = u"bar"; |
| 1248 | ``` |
| 1249 | |
| 1250 | **Description:** A non-owning reference to a string. Useful for providing an |
| 1251 | abstraction on top of strings (e.g. for parsing). |
| 1252 | |
| 1253 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1254 | [`std::basic_string_view`](https://en.cppreference.com/w/cpp/string/basic_string_view) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1255 | |
| 1256 | **Notes:** |
| 1257 | *** promo |
| 1258 | [Will be allowed soon](https://crbug.com/691162); for now, use |
| 1259 | `base::StringPiece[16]`. |
| 1260 | *** |
| 1261 | |
| 1262 | ### std::uncaught_exceptions <sup>[banned]</sup> |
| 1263 | |
| 1264 | ```c++ |
| 1265 | int count = std::uncaught_exceptions(); |
| 1266 | ``` |
| 1267 | |
| 1268 | **Description:** Determines whether there are live exception objects. |
| 1269 | |
| 1270 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1271 | [`std::uncaught_exceptions`](https://en.cppreference.com/w/cpp/error/uncaught_exception) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1272 | |
| 1273 | **Notes:** |
| 1274 | *** promo |
| 1275 | Banned because exceptions are banned. |
| 1276 | *** |
| 1277 | |
| 1278 | ### std::variant <sup>[banned]</sup> |
| 1279 | |
| 1280 | ```c++ |
| 1281 | std::variant<int, double> v = 12; |
| 1282 | ``` |
| 1283 | |
| 1284 | **Description:** The class template `std::variant` represents a type-safe |
| 1285 | `union`. An instance of `std::variant` at any given time holds a value of one of |
| 1286 | its alternative types (it's also possible for it to be valueless). |
| 1287 | |
| 1288 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1289 | [`std::variant`](https://en.cppreference.com/w/cpp/utility/variant) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1290 | |
| 1291 | **Notes:** |
| 1292 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1293 | [Will be allowed soon](https://crbug.com/1373620); for now, use `absl::variant`. |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1294 | *** |
| 1295 | |
| 1296 | ### Transparent std::owner_less <sup>[banned]</sup> |
| 1297 | |
| 1298 | ```c++ |
| 1299 | std::map<std::weak_ptr<T>, U, std::owner_less<>> |
| 1300 | ``` |
| 1301 | |
| 1302 | **Description:** Function object providing mixed-type owner-based ordering of |
| 1303 | shared and weak pointers, regardless of the type of the pointee. |
| 1304 | |
| 1305 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1306 | [`std::owner_less`](https://en.cppreference.com/w/cpp/memory/owner_less) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1307 | |
| 1308 | **Notes:** |
| 1309 | *** promo |
| 1310 | Banned since `std::shared_ptr` and `std::weak_ptr` are banned. |
| 1311 | *** |
| 1312 | |
| 1313 | ### weak_from_this <sup>[banned]</sup> |
| 1314 | |
| 1315 | ```c++ |
| 1316 | auto weak_ptr = weak_from_this(); |
| 1317 | ``` |
| 1318 | |
| 1319 | **Description:** Returns a `std::weak_ptr<T>` that tracks ownership of `*this` |
| 1320 | by all existing `std::shared_ptr`s that refer to `*this`. |
| 1321 | |
| 1322 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1323 | [`std::enable_shared_from_this<T>::weak_from_this`](https://en.cppreference.com/w/cpp/memory/enable_shared_from_this/weak_from_this) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1324 | |
| 1325 | **Notes:** |
| 1326 | *** promo |
| 1327 | Banned since `std::shared_ptr` and `std::weak_ptr` are banned. |
Avi Drissman | 37b7d51 | 2022-04-01 22:01:40 | [diff] [blame] | 1328 | *** |
| 1329 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1330 | ## C++17 TBD Language Features {#core-review-17} |
| 1331 | |
| 1332 | The following C++17 language features are not allowed in the Chromium codebase. |
| 1333 | See the top of this page on how to propose moving a feature from this list into |
| 1334 | the allowed or banned sections. |
| 1335 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1336 | ### UTF-8 character literals <sup>[tbd]</sup> |
| 1337 | |
| 1338 | ```c++ |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1339 | char x = u8'x'; // C++17 |
| 1340 | char8_t x = u8'x'; // C++20 |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1341 | ``` |
| 1342 | |
| 1343 | **Description:** A character literal that begins with `u8` is a character |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1344 | literal of type `char` (C++17) or `char8_t` (C++20). The value of a UTF-8 |
| 1345 | character literal is equal to its ISO 10646 code point value. |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1346 | |
| 1347 | **Documentation:** |
| 1348 | [Character literal](https://en.cppreference.com/w/cpp/language/character_literal) |
| 1349 | |
| 1350 | **Notes:** |
| 1351 | *** promo |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1352 | None |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1353 | *** |
| 1354 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1355 | ## C++17 TBD Library Features {#library-review-17} |
| 1356 | |
| 1357 | The following C++17 library features are not allowed in the Chromium codebase. |
| 1358 | See the top of this page on how to propose moving a feature from this list into |
| 1359 | the allowed or banned sections. |
| 1360 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1361 | ### Mathematical special functions <sup>[tbd]</sup> |
| 1362 | |
| 1363 | ```c++ |
| 1364 | std::assoc_laguerre() |
| 1365 | std::assoc_legendre() |
| 1366 | std::beta() |
| 1367 | std::comp_ellint_1() |
| 1368 | std::comp_ellint_2() |
| 1369 | std::comp_ellint_3() |
| 1370 | std::cyl_bessel_i() |
| 1371 | std::cyl_bessel_j() |
| 1372 | std::cyl_bessel_k() |
| 1373 | std::cyl_neumann() |
| 1374 | std::ellint_1() |
| 1375 | std::ellint_2() |
| 1376 | std::ellint_3() |
| 1377 | std::expint() |
| 1378 | std::hermite() |
| 1379 | std::legendre() |
| 1380 | std::laguerre() |
| 1381 | std::riemann_zeta() |
| 1382 | std::sph_bessel() |
| 1383 | std::sph_legendre() |
| 1384 | std::sph_neumann() |
| 1385 | ``` |
| 1386 | |
| 1387 | **Description:** A variety of mathematical functions. |
| 1388 | |
| 1389 | **Documentation:** |
| 1390 | [Mathematical special functions](https://en.cppreference.com/w/cpp/numeric/special_functions) |
| 1391 | |
| 1392 | **Notes:** |
| 1393 | *** promo |
| 1394 | May not be supported in libc++, according to the |
| 1395 | [library features table](https://en.cppreference.com/w/cpp/17) |
| 1396 | *** |
| 1397 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1398 | ### Parallel algorithms <sup>[tbd]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1399 | |
| 1400 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1401 | auto it = std::find(std::execution::par, std::begin(vec), std::end(vec), 2); |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1402 | ``` |
| 1403 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1404 | **Description:** Many of the STL algorithms, such as the `copy`, `find` and |
| 1405 | `sort` methods, now support the parallel execution policies: `seq`, `par`, and |
| 1406 | `par_unseq` which translate to "sequentially", "parallel" and |
| 1407 | "parallel unsequenced". |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1408 | |
| 1409 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1410 | [`std::execution::sequenced_policy`, `std::execution::parallel_policy`, `std::execution::parallel_unsequenced_policy`, `std::execution::unsequenced_policy`](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1411 | |
| 1412 | **Notes:** |
| 1413 | *** promo |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1414 | May not be supported in libc++, according to the |
| 1415 | [library features table](https://en.cppreference.com/w/cpp/17) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1416 | *** |
| 1417 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1418 | ### std::byte <sup>[tbd]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1419 | |
| 1420 | ```c++ |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1421 | std::byte b = 0xFF; |
| 1422 | int i = std::to_integer<int>(b); // 0xFF |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1423 | ``` |
| 1424 | |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1425 | **Description:** A standard way of representing data as a byte. `std::byte` is |
| 1426 | neither a character type nor an arithmetic type, and the only operator overloads |
| 1427 | available are bitwise operations. |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1428 | |
| 1429 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1430 | [`std::byte`](https://en.cppreference.com/w/cpp/types/byte) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1431 | |
| 1432 | **Notes:** |
| 1433 | *** promo |
| 1434 | No current consensus; see |
| 1435 | [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/bBY0gZa1Otk). |
| 1436 | *** |
| 1437 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1438 | ### std::{pmr::memory_resource,polymorphic_allocator} <sup>[tbd]</sup> |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1439 | |
| 1440 | ```c++ |
| 1441 | #include <memory_resource> |
| 1442 | ``` |
| 1443 | |
| 1444 | **Description:** Manages memory allocations using runtime polymorphism. |
| 1445 | |
| 1446 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1447 | [`std::pmr::memory_resource`](https://en.cppreference.com/w/cpp/memory/memory_resource), |
| 1448 | [`std::pmr::polymorphic_allocator`](https://en.cppreference.com/w/cpp/memory/polymorphic_allocator) |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1449 | |
| 1450 | **Notes:** |
| 1451 | *** promo |
| 1452 | May not be supported in libc++, according to the |
| 1453 | [library features table](https://en.cppreference.com/w/cpp/17) |
| 1454 | *** |
| 1455 | |
| 1456 | ### std::reduce <sup>[tbd]</sup> |
| 1457 | |
| 1458 | ```c++ |
| 1459 | std::reduce(std::execution::par, v.cbegin(), v.cend()); |
| 1460 | ``` |
| 1461 | |
| 1462 | **Description:** Like `std::accumulate` except the elements of the range may be |
| 1463 | grouped and rearranged in arbitrary order. |
| 1464 | |
| 1465 | **Documentation:** |
| 1466 | [std::reduce](https://en.cppreference.com/w/cpp/algorithm/reduce) |
| 1467 | |
| 1468 | **Notes:** |
| 1469 | *** promo |
| 1470 | Makes the most sense in conjunction with `std::execution::par`. |
| 1471 | *** |
| 1472 | |
| 1473 | ### std::timespec_get <sup>[tbd]</sup> |
| 1474 | |
| 1475 | ```c++ |
| 1476 | std::timespec ts; |
| 1477 | std::timespec_get(&ts, TIME_UTC); |
| 1478 | ``` |
| 1479 | |
| 1480 | **Description:** Gets the current calendar time in the given time base. |
| 1481 | |
| 1482 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1483 | [`std::timespec_get`](https://en.cppreference.com/w/cpp/chrono/c/timespec_get) |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1484 | |
| 1485 | **Notes:** |
| 1486 | *** promo |
| 1487 | None |
| 1488 | *** |
| 1489 | |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1490 | ### std::{from,to}_chars <sup>[tbd]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1491 | |
| 1492 | ```c++ |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1493 | std::from_chars(str.data(), str.data() + str.size(), result); |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1494 | std::to_chars(str.data(), str.data() + str.size(), 42); |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1495 | ``` |
| 1496 | |
| 1497 | **Description:** Locale-independent, non-allocating, non-throwing functions to |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1498 | convert values from/to character strings, designed for use in high-throughput |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1499 | contexts. |
| 1500 | |
| 1501 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1502 | [`std::from_chars`](https://en.cppreference.com/w/cpp/utility/from_chars) |
| 1503 | [`std::to_chars`](https://en.cppreference.com/w/cpp/utility/to_chars), |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1504 | |
| 1505 | **Notes:** |
| 1506 | *** promo |
| 1507 | None |
| 1508 | *** |
| 1509 | |
Arthur Sonzogni | d8517c9 | 2023-03-03 09:41:45 | [diff] [blame^] | 1510 | ## C++20 Allowed Language Features {#core-allowlist-20} |
| 1511 | |
| 1512 | ### Designated initializers <sup>[allowed]</sup> |
| 1513 | |
| 1514 | ```c++ |
| 1515 | struct S { int x = 1; int y = 2; } |
| 1516 | S s{ .y = 3 }; // OK, s.x == 1, s.y == 3 |
| 1517 | ``` |
| 1518 | |
| 1519 | **Description:** Allows explicit initialization of subsets of aggregate members |
| 1520 | at construction. |
| 1521 | |
| 1522 | **Documentation:** |
| 1523 | [Designated initializers](https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers) |
| 1524 | |
| 1525 | **Notes:** |
| 1526 | *** promo |
| 1527 | None |
| 1528 | *** |
| 1529 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1530 | ## Abseil Banned Library Features {#absl-blocklist} |
| 1531 | |
| 1532 | The following Abseil library features are not allowed in the Chromium codebase. |
| 1533 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1534 | ### Any <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1535 | |
| 1536 | ```c++ |
| 1537 | absl::any a = int{5}; |
| 1538 | EXPECT_THAT(absl::any_cast<int>(&a), Pointee(5)); |
| 1539 | EXPECT_EQ(absl::any_cast<size_t>(&a), nullptr); |
| 1540 | ``` |
| 1541 | |
| 1542 | **Description:** Early adaptation of C++17 `std::any`. |
| 1543 | |
| 1544 | **Documentation:** [std::any](https://en.cppreference.com/w/cpp/utility/any) |
| 1545 | |
| 1546 | **Notes:** |
| 1547 | *** promo |
| 1548 | Banned since workaround for lack of RTTI isn't compatible with the component |
Daniel Cheng | c05fcc6 | 2022-01-12 16:54:29 | [diff] [blame] | 1549 | build ([Bug](https://crbug.com/1096380)). Also see `std::any`. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1550 | *** |
| 1551 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1552 | ### bind_front <sup>[banned]</sup> |
| 1553 | |
| 1554 | ```c++ |
| 1555 | absl::bind_front |
| 1556 | ``` |
| 1557 | |
| 1558 | **Description:** Binds the first N arguments of an invocable object and stores them by value. |
| 1559 | |
| 1560 | **Documentation:** |
| 1561 | * [bind_front.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/bind_front.h) |
| 1562 | * [Avoid std::bind](https://abseil.io/tips/108) |
| 1563 | |
| 1564 | **Notes:** |
| 1565 | *** promo |
| 1566 | Banned due to overlap with `base::Bind`. Use `base::Bind` instead. |
| 1567 | *** |
| 1568 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1569 | ### Command line flags <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1570 | |
| 1571 | ```c++ |
| 1572 | ABSL_FLAG(bool, logs, false, "print logs to stderr"); |
| 1573 | app --logs=true; |
| 1574 | ``` |
| 1575 | |
| 1576 | **Description:** Allows programmatic access to flag values passed on the |
| 1577 | command-line to binaries. |
| 1578 | |
| 1579 | **Documentation:** [Flags Library](https://abseil.io/docs/cpp/guides/flags) |
| 1580 | |
| 1581 | **Notes:** |
| 1582 | *** promo |
| 1583 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 1584 | build. ([Bug](https://crbug.com/1096380)) Use `base::CommandLine` instead. |
| 1585 | *** |
| 1586 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1587 | ### Container utilities <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1588 | |
| 1589 | ```c++ |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1590 | auto it = absl::c_find(container, value); |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1591 | ``` |
| 1592 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1593 | **Description:** Container-based versions of algorithmic functions within C++ |
| 1594 | standard library. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1595 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1596 | **Documentation:** |
| 1597 | [container.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/algorithm/container.h) |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1598 | |
| 1599 | **Notes:** |
| 1600 | *** promo |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1601 | Banned due to overlap with `base/ranges/algorithm.h`. Use the `base/ranges/` |
| 1602 | facilities instead. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1603 | *** |
| 1604 | |
Daniel Cheng | 2248b33 | 2022-07-27 06:16:59 | [diff] [blame] | 1605 | ### FunctionRef <sup>[banned]</sup> |
| 1606 | |
| 1607 | ```c++ |
| 1608 | absl::FunctionRef |
| 1609 | ``` |
| 1610 | |
| 1611 | **Description:** Type for holding a non-owning reference to an object of any |
| 1612 | invocable type. |
| 1613 | |
| 1614 | **Documentation:** |
| 1615 | [function_ref.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/function_ref.h) |
| 1616 | |
| 1617 | **Notes:** |
| 1618 | *** promo |
| 1619 | - `absl::FunctionRef` is banned due to allowing implicit conversions between |
| 1620 | function signatures in potentially surprising ways. For example, a callable |
| 1621 | with the signature `int()` will bind to `absl::FunctionRef<void()>`: the |
| 1622 | return value from the callable will be silently discarded. |
| 1623 | - In Chromium, use `base::FunctionRef` instead. |
| 1624 | - Unlike `base::OnceCallback` and `base::RepeatingCallback`, `base::FunctionRef` |
| 1625 | supports capturing lambdas. |
| 1626 | - Useful when passing an invocable object to a function that synchronously calls |
| 1627 | the invocable object, e.g. `ForEachFrame(base::FunctionRef<void(Frame&)>)`. |
| 1628 | This can often result in clearer code than code that is templated to accept |
| 1629 | lambdas, e.g. with `template <typename Invocable> void |
| 1630 | ForEachFrame(Invocable invocable)`, it is much less obvious what arguments |
| 1631 | will be passed to `invocable`. |
| 1632 | - For now, `base::OnceCallback` and `base::RepeatingCallback` intentionally |
| 1633 | disallow conversions to `base::FunctionRef`, under the theory that the |
| 1634 | callback should be a capturing lambda instead. Attempting to use this |
| 1635 | conversion will trigger a `static_assert` requesting additional feedback for |
| 1636 | use cases where this conversion would be valuable. |
| 1637 | - *Important:* `base::FunctionRef` must not outlive the function call. Like |
| 1638 | `base::StringPiece`, `base::FunctionRef` is a *non-owning* reference. Using a |
| 1639 | `base::FunctionRef` as a return value or class field is dangerous and likely |
| 1640 | to result in lifetime bugs. |
Peter Kasting | 6d77e9d | 2023-02-09 21:58:18 | [diff] [blame] | 1641 | - [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JVN4E4IIYA0) |
Daniel Cheng | 2248b33 | 2022-07-27 06:16:59 | [diff] [blame] | 1642 | *** |
| 1643 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1644 | ### Random <sup>[banned]</sup> |
| 1645 | |
| 1646 | ```c++ |
| 1647 | absl::BitGen bitgen; |
| 1648 | size_t index = absl::Uniform(bitgen, 0u, elems.size()); |
| 1649 | ``` |
| 1650 | |
| 1651 | **Description:** Functions and utilities for generating pseudorandom data. |
| 1652 | |
| 1653 | **Documentation:** [Random library](https://abseil.io/docs/cpp/guides/random) |
| 1654 | |
| 1655 | **Notes:** |
| 1656 | *** promo |
| 1657 | Banned because most uses of random values in Chromium should be using a |
| 1658 | cryptographically secure generator. Use `base/rand_util.h` instead. |
| 1659 | *** |
| 1660 | |
| 1661 | ### Span <sup>[banned]</sup> |
| 1662 | |
| 1663 | ```c++ |
| 1664 | absl::Span |
| 1665 | ``` |
| 1666 | |
| 1667 | **Description:** Early adaptation of C++20 `std::span`. |
| 1668 | |
| 1669 | **Documentation:** [Using absl::Span](https://abseil.io/tips/93) |
| 1670 | |
| 1671 | **Notes:** |
| 1672 | *** promo |
| 1673 | Banned due to being less std::-compliant than `base::span`. Keep using |
| 1674 | `base::span`. |
| 1675 | *** |
| 1676 | |
| 1677 | ### StatusOr <sup>[banned]</sup> |
| 1678 | |
| 1679 | ```c++ |
| 1680 | absl::StatusOr<T> |
| 1681 | ``` |
| 1682 | |
| 1683 | **Description:** An object that is either a usable value, or an error Status |
| 1684 | explaining why such a value is not present. |
| 1685 | |
| 1686 | **Documentation:** |
| 1687 | [statusor.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/statusor.h) |
| 1688 | |
| 1689 | **Notes:** |
| 1690 | *** promo |
| 1691 | Banned due to overlap with `base::expected`. Use `base::expected` instead. |
| 1692 | *** |
| 1693 | |
| 1694 | ### String Formatting <sup>[banned]</sup> |
| 1695 | |
| 1696 | ```c++ |
| 1697 | absl::StrFormat |
| 1698 | ``` |
| 1699 | |
| 1700 | **Description:** A typesafe replacement for the family of printf() string |
| 1701 | formatting routines. |
| 1702 | |
| 1703 | **Documentation:** |
| 1704 | [String Formatting](https://abseil.io/docs/cpp/guides/format) |
| 1705 | |
| 1706 | **Notes:** |
| 1707 | *** promo |
| 1708 | Banned for now due to overlap with `base::StringPrintf()`. See |
| 1709 | [migration bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1371963). |
| 1710 | *** |
| 1711 | |
| 1712 | ### string_view <sup>[banned]</sup> |
| 1713 | |
| 1714 | ```c++ |
| 1715 | absl::string_view |
| 1716 | ``` |
| 1717 | |
| 1718 | **Description:** Early adaptation of C++17 `std::string_view`. |
| 1719 | |
| 1720 | **Documentation:** [absl::string_view](https://abseil.io/tips/1) |
| 1721 | |
| 1722 | **Notes:** |
| 1723 | *** promo |
| 1724 | Banned due to only working with 8-bit characters. Keep using |
| 1725 | `base::StringPiece` from `base/strings/`. |
| 1726 | *** |
| 1727 | |
| 1728 | ### Strings Library <sup>[banned]</sup> |
| 1729 | |
| 1730 | ```c++ |
| 1731 | absl::StrSplit |
| 1732 | absl::StrJoin |
| 1733 | absl::StrCat |
| 1734 | absl::StrAppend |
| 1735 | absl::Substitute |
| 1736 | absl::StrContains |
| 1737 | ``` |
| 1738 | |
| 1739 | **Description:** Classes and utility functions for manipulating and comparing |
| 1740 | strings. |
| 1741 | |
| 1742 | **Documentation:** |
| 1743 | [String Utilities](https://abseil.io/docs/cpp/guides/strings) |
| 1744 | |
| 1745 | **Notes:** |
| 1746 | *** promo |
| 1747 | Banned for now due to overlap with `base/strings`. We |
| 1748 | [should re-evalute](https://bugs.chromium.org/p/chromium/issues/detail?id=1371966) |
| 1749 | when we've |
| 1750 | [migrated](https://bugs.chromium.org/p/chromium/issues/detail?id=691162) from |
| 1751 | `base::StringPiece` to `std::string_view`. |
| 1752 | *** |
| 1753 | |
| 1754 | ### Synchronization <sup>[banned]</sup> |
| 1755 | |
| 1756 | ```c++ |
| 1757 | absl::Mutex |
| 1758 | ``` |
| 1759 | |
| 1760 | **Description:** Primitives for managing tasks across different threads. |
| 1761 | |
| 1762 | **Documentation:** |
| 1763 | [Synchronization](https://abseil.io/docs/cpp/guides/synchronization) |
| 1764 | |
| 1765 | **Notes:** |
| 1766 | *** promo |
| 1767 | Banned due to overlap with `base/synchronization/`. We would love |
| 1768 | [more testing](https://bugs.chromium.org/p/chromium/issues/detail?id=1371969) on |
| 1769 | whether there are compelling reasons to prefer base, absl, or std |
| 1770 | synchronization primitives; for now, use `base/synchronization/`. |
| 1771 | *** |
| 1772 | |
| 1773 | ### Time library <sup>[banned]</sup> |
| 1774 | |
| 1775 | ```c++ |
| 1776 | absl::Duration |
| 1777 | absl::Time |
| 1778 | absl::TimeZone |
| 1779 | absl::CivilDay |
| 1780 | ``` |
| 1781 | |
| 1782 | **Description:** Abstractions for holding time values, both in terms of |
| 1783 | absolute time and civil time. |
| 1784 | |
| 1785 | **Documentation:** [Time](https://abseil.io/docs/cpp/guides/time) |
| 1786 | |
| 1787 | **Notes:** |
| 1788 | *** promo |
| 1789 | Banned due to overlap with `base/time/`. Use `base/time/` instead. |
| 1790 | *** |
| 1791 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1792 | ## Abseil TBD Features {#absl-review} |
| 1793 | |
| 1794 | The following Abseil library features are not allowed in the Chromium codebase. |
| 1795 | See the top of this page on how to propose moving a feature from this list into |
| 1796 | the allowed or banned sections. |
| 1797 | |
Danil Chapovalov | a9f2703 | 2022-06-20 16:56:14 | [diff] [blame] | 1798 | ### AnyInvocable <sup>[tbd]</sup> |
| 1799 | |
| 1800 | ```c++ |
| 1801 | absl::AnyInvocable |
| 1802 | ``` |
| 1803 | |
| 1804 | **Description:** An equivalent of the C++23 std::move_only_function. |
| 1805 | |
| 1806 | **Documentation:** |
| 1807 | * [any_invocable.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/any_invocable.h) |
| 1808 | * [std::move_only_function](https://en.cppreference.com/w/cpp/utility/functional/move_only_function/move_only_function) |
| 1809 | |
| 1810 | **Notes:** |
| 1811 | *** promo |
| 1812 | Overlaps with `base::RepeatingCallback`, `base::OnceCallback`. |
| 1813 | *** |
| 1814 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1815 | ### Containers <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1816 | |
| 1817 | ```c++ |
| 1818 | absl::flat_hash_map |
| 1819 | absl::flat_hash_set |
| 1820 | absl::node_hash_map |
| 1821 | absl::node_hash_set |
| 1822 | absl::btree_map |
| 1823 | absl::btree_set |
| 1824 | absl::btree_multimap |
| 1825 | absl::btree_multiset |
| 1826 | absl::InlinedVector |
| 1827 | absl::FixedArray |
| 1828 | ``` |
| 1829 | |
| 1830 | **Description:** Alternatives to STL containers designed to be more efficient |
| 1831 | in the general case. |
| 1832 | |
| 1833 | **Documentation:** |
| 1834 | * [Containers](https://abseil.io/docs/cpp/guides/container) |
| 1835 | * [Hash](https://abseil.io/docs/cpp/guides/hash) |
| 1836 | |
| 1837 | **Notes:** |
| 1838 | *** promo |
| 1839 | Supplements `base/containers/`. |
| 1840 | *** |
| 1841 | |
Mirko Bonadei | de812cd | 2022-12-07 22:38:32 | [diff] [blame] | 1842 | ### CRC32C library <sup>[tbd]</sup> |
| 1843 | |
| 1844 | **Description:** API for computing CRC32C values as checksums for arbitrary |
| 1845 | sequences of bytes provided as a string buffer. |
| 1846 | |
| 1847 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1848 | [crc32.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/crc/crc32c.h) |
Mirko Bonadei | de812cd | 2022-12-07 22:38:32 | [diff] [blame] | 1849 | |
| 1850 | **Notes:** |
| 1851 | *** promo |
| 1852 | Overlaps with //third_party/crc32c. |
| 1853 | *** |
| 1854 | |
Peter Kasting | 4f35bfc | 2022-10-18 18:39:12 | [diff] [blame] | 1855 | ### Log macros and related classes <sup>[tbd]</sup> |
Danil Chapovalov | 6719fb1 | 2022-08-31 13:52:49 | [diff] [blame] | 1856 | |
| 1857 | ```c++ |
| 1858 | LOG(INFO) << message; |
| 1859 | CHECK(condition); |
| 1860 | absl::AddLogSink(&custom_sink_to_capture_absl_logs); |
| 1861 | ``` |
| 1862 | |
| 1863 | **Description:** Macros and related classes to perform debug loggings |
| 1864 | |
| 1865 | **Documentation:** |
Peter Kasting | e2c5ee8 | 2023-02-15 17:23:08 | [diff] [blame] | 1866 | [log.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/log/log.h) |
| 1867 | [check.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/log/check.h) |
Danil Chapovalov | 6719fb1 | 2022-08-31 13:52:49 | [diff] [blame] | 1868 | |
| 1869 | **Notes:** |
| 1870 | *** promo |
| 1871 | Overlaps and uses same macros names as `base/logging.h`. |
| 1872 | *** |