C++ use in Chromium
This document lives at src/styleguide/c++/c++11.html in a Chromium checkout and is part of the more general Chromium C++ style guide. It summarizes the supported state of new and updated language and library features in recent C++ standards. This guide applies to both Chromium and its subprojects, though subprojects can choose to be more restrictive if necessary for toolchain support.
The C++ language has in recent years received an updated standard every three years (C++11, C++14, C++17). For various reasons, Chromium does not immediately allow new features on the publication of such a standard. Instead, once toolchain support is sufficient, a standard is declared "initially supported", with new language/library features banned pending discussion.
You can propose changing the status of a feature by sending an email to firstname.lastname@example.org. Include a short blurb on what the feature is and why you think it should or should not be allowed, along with links to any relevant previous discussion. If the list arrives at some consensus, send a codereview to change this file accordingly, linking to your discussion thread.
Two years after a standard is initially supported in Chromium, style arbiters should make a final decision on any remaining TBD features to be banned, then default-allow all non-banned portions of the standard. The current status of existing standards is:
- C++11: Default allowed; see banned features below
- C++14: Default allowed; see banned features below
- C++17: Not yet supported in Chromium
- C++20: Not yet standardized
Table of Contents
The following C++11 language features are not allowed in the Chromium codebase.
|Feature or Library||Snippet||Description||Documentation Link||Notes and Discussion Thread|
||Allows better versioning of namespaces||Inline namespaces||Banned in the Google Style Guide. Unclear how it will work with components.|
||An integer of at least 64 bits||Fundamental types||Use a stdint.h type if you need a 64-bit number. Discussion thread|
||Allows user-defined literal expressions||User-defined literals||Banned in the Google Style Guide.|
|thread_local storage class||
||Puts variables into thread local storage.||Storage duration||Some surprising effects on Mac (discussion, fork). Use
The following C++11 library features are not allowed in the Chromium codebase.
|Feature||Snippet||Description||Documentation Link||Notes and Discussion Thread||Bind Operations||
||Declares a function object bound to certain arguments||std::bind||Use
|C Floating-Point Environment||
||Provides floating point status flags and control modes for C-compatible code||Standard library header <cfenv>||Banned by the Google Style Guide due to concerns about compiler support.|
|Date and time utilities||
||A standard date and time library||Date and time utilities||Overlaps with
||Enhancements to exception throwing and handling||Standard library header <exception>||Exceptions are banned by the Google Style Guide and disabled in Chromium compiles. However, the
||Wraps a standard polymorphic function||std::function||Use
|Random Number Engines||The random number engines defined in
||Random number generation algorithms and utilities.||Pseudo-random number generation||Do not use any random number engines from
|Ratio Template Class||
||Provides compile-time rational numbers||std::ratio||Banned by the Google Style Guide due to concerns that this is tied to a more template-heavy interface style.|
||A standard regular expressions library||Regular expressions library||Overlaps with many regular expression libraries in Chromium. When in doubt, use re2.|
||Allows shared ownership of a pointer through reference counts||std::shared_ptr||Needs a lot more evaluation for Chromium, and there isn't enough of a push for this feature. Google Style Guide. Discussion Thread|
|String-Number Conversion Functions||
||Converts strings to/from numbers||std::stoi, std::stol, std::stoll, std::stoul, std::stoull, std::stof, std::stod, std::stold, std::to_string||The string-to-number conversions rely on exceptions to communicate failure, while the number-to-string conversions have performance concerns and depend on the locale. Use the routines in
||Provides a standard multithreading library using
||Thread support library||Overlaps with many classes in
||Allows a weak reference to a
The following C++14 library features are not allowed in the Chromium codebase.
|Feature||Snippet||Description||Documentation Link||Notes and Discussion Thread|