C++ Standards Support in GCC#
Warning
The page was automatically converted by pandoc tool!
GCC supports different dialects of C++, corresponding to the multiple
published ISO standards. Which standard it implements can be selected
using the -std=
command-line option.
For information about the status of C++ defect reports, please see this page.
For information about the status of the library implementation, please see the Implementation Status section of the Libstdc++ manual.
C++23 Support in GCC#
GCC has experimental support for the next revision of the C++ standard, which is expected to be published in 2023.
C++23 features are available since GCC 11. To enable C++23 support, add
the command-line parameter -std=c++2b
to your g++
command line.
Or, to enable GNU extensions in addition to C++23 features, add
-std=gnu++2b
.
Important: Because the ISO C++23 standard is still evolving, GCC’s support is experimental. No attempt will be made to maintain backward compatibility with implementations of C++23 features that do not reflect the final standard.
C++23 Language Features#
Language Feature |
Proposal |
Available in GCC? |
SD-6 Feature Test |
---|---|---|---|
Literal Suffix for (signed) size_t |
__cpp_size_t_suffix >= 202006L |
||
Make () more optional for lambdas |
|||
DR: Declarations and where to find them |
|||
|
__cpp_if_consteval >= 202106L |
||
C++ Identifier Syntax using Unicode Standard Annex 31 |
|||
Allow Duplicate Attributes |
|||
Narrowing contextual conversions to bool |
9 |
||
Trimming whitespaces before line splicing |
Yes |
||
Mixed string literal concatenation |
Yes |
||
Make declaration order layout mandated |
Yes |
||
Removing Garbage Collection Support |
|||
Simpler implicit move |
__cpp_implicit_move >= 202207L |
||
Deducing this |
__cpp_explicit_this_parameter >= 202110L |
||
Change scope of lambda trailing-return-type |
|||
Multidimensional subscript operator |
__cpp_multidimensional_subscript >= 202110L |
||
|
__cpp_constexpr >= 202110L |
||
Character encoding of diagnostic text |
|||
Character sets and encodings |
|||
Consistent character literal encoding |
Yes |
||
Add support for preprocessing directives elifdef and elifndef |
|||
Extend init-statement to allow alias-declaration |
|||
auto(x): decay-copy in the language |
|||
Labels at the end of compound statements |
|||
CWG 2397: auto specifier for pointers and references to arrays |
|||
|
Yes |
||
Attributes on lambda-expressions |
9 |
||
A type trait to detect reference binding to temporary |
|||
The Equality Operator You Are Looking For |
|||
De-deprecating volatile compound operations |
|||
Support for |
|
||
|
|||
Delimited escape sequences |
|||
Named universal character escapes |
__cpp_named_character_escapes >= 202207L |
||
Relaxing some constexpr restrictions |
__cpp_constexpr >= 202207L |
||
Using unknown references in constant expressions |
|||
static |
__cpp_static_call_operator >= 202207L |
||
Extended floating-point types and standard names |
|||
Class template argument deduction from inherited constructors |
|||
Portable assumptions |
|||
Support for UTF-8 as a portable source file encoding |
|||
|
__cpp_char8_t >= 202207L |
||
Relax requirements on |
Yes |
||
Explicit lifetime management |
C++20 Support in GCC#
GCC has experimental support for the latest revision of the C++ standard, which was published in 2020.
C++20 features are available since GCC 8. To enable C++20 support, add
the command-line parameter -std=c++20
(use -std=c++2a
in GCC 9
and earlier) to your g++
command line. Or, to enable GNU extensions
in addition to C++20 features, add -std=gnu++20
.
Important: Because the ISO C++20 standard is very recent, GCC’s support is experimental.
C++20 Language Features#
The following table lists new language features that have been accepted into the C++20 working draft. The “Proposal” column provides a link to the ISO C++ committee proposal that describes the feature, while the “Available in GCC?” column indicates the first version of GCC that contains an implementation of this feature (if it has been implemented).
Language Feature |
Proposal |
Available in GCC? |
SD-6 Feature Test |
---|---|---|---|
Default member initializers for bit-fields |
|||
Fixing const-qualified pointers to members |
|||
Allow lambda capture |
|||
|
|||
Designated initializers |
__cpp_designated_initializers >= 201707 |
||
Familiar template syntax for generic lambdas |
__cpp_generic_lambdas >= 201707 |
||
List deduction of vector |
|||
Concepts |
__cpp_concepts >= 201907 |
||
__cpp_concepts >= 202002 |
|||
__cpp_concepts >= 201907 |
|||
|
|||
Range-based for statements with initializer |
|||
Simplifying implicit lambda capture |
|||
ADL and function templates that are not visible |
|||
|
|||
Less eager instantiation of |
|
__cpp_constexpr_in_decltype >= 201711 |
|
Consistent comparison ( |
__cpp_impl_three_way_comparison >= 201711 |
||
Access checking on specializations |
Yes |
||
Default constructible and assignable stateless lambdas |
|||
Lambdas in unevaluated contexts |
|||
Language support for empty objects |
|||
Relaxing the range-for loop customization point finding rules |
|||
Allow structured bindings to accessible members |
|||
|
|||
Down with typename! |
|||
Allow pack expansion in lambda init-capture |
__cpp_init_captures >= 201803 |
||
Proposed wording for likely and unlikely attributes |
|||
Deprecate implicit capture of this via [=] |
|||
Class Types in Non-Type Template Parameters |
__cpp_nontype_template_parameter_class >= 201806 |
||
Inconsistencies with non-type template parameters |
__cpp_nontype_template_args >= 201911 |
||
Atomic Compare-and-Exchange with Padding Bits |
|||
Efficient sized delete for variable sized classes |
__cpp_impl_destroying_delete >= 201806 |
||
Allowing Virtual Function Calls in Constant Expressions |
|||
Prohibit aggregates with user-declared constructors |
|||
explicit(bool) |
__cpp_conditional_explicit >= 201806 |
||
Signed integers are two’s complement |
|||
char8_t |
__cpp_char8_t >= 201811 |
||
Immediate functions (consteval) |
__cpp_consteval >= 201811 |
||
std::is_constant_evaluated |
|||
Nested inline namespaces |
|||
Relaxations of constexpr restrictions |
|||
__cpp_constexpr >= 202002 |
|||
__cpp_constexpr >= 201907 |
|||
__cpp_constexpr_dynamic_alloc >= 201907 |
|||
Feature test macros |
|||
Modules |
|
|
|
No |
|||
P1703R1 (superceded by p1857) |
|||
No |
|||
Coroutines |
10 (requires -fcoroutines) |
__cpp_impl_coroutine >= 201902 |
|
Parenthesized initialization of aggregates |
__cpp_aggregate_paren_init >= 201902 |
||
DR: array size deduction in new-expression |
|||
|
|||
Stronger Unicode requirements |
|||
Structured binding extensions |
|||
Deprecate |
|||
Deprecating some uses of |
|||
|
|||
|
|||
Class template argument deduction for aggregates |
__cpp_deduction_guides >= 201907L |
||
Class template argument deduction for alias templates |
|||
Permit conversions to arrays of unknown bound |
|||
|
__cpp_constinit >= 201907 |
||
Layout-compatibility and Pointer-interconvertibility Traits |
(in library) |
||
DR: Checking for abstract class types |
|||
DR: More implicit moves (merge P0527R1 and P1155R3) |
11 (C++20 mode) |
||
DR: Pseudo-destructors end object lifetimes |
C++17 Support in GCC#
GCC has almost full support for the previous revision of the C++ standard, which was published in 2017. Some library features are missing or incomplete, as described in the library documentation.
C++17 features are available since GCC 5. This mode is the default in
GCC 11; it can be explicitly selected with the -std=c++17
command-line flag, or -std=gnu++17
to enable GNU extensions as well.
C++17 Language Features#
The following table lists new language features that have been accepted into the C++17 working draft. The “Proposal” column provides a link to the ISO C++ committee proposal that describes the feature, while the “Available in GCC?” column indicates the first version of GCC that contains an implementation of this feature (if it has been implemented).
Language Feature |
Proposal |
Available in GCC? |
SD-6 Feature Test |
---|---|---|---|
Removing trigraphs |
|||
|
__cpp_unicode_characters >= 201411 |
||
Folding expressions |
__cpp_fold_expressions >= 201411 |
||
Attributes for namespaces and enumerators |
|
||
Nested namespace definitions |
__cpp_nested_namespace_definitions >= 201411 |
||
Allow constant evaluation for all non-type template arguments |
__cpp_nontype_template_args >= 201411 |
||
Extending |
__cpp_static_assert >= 201411 |
||
New Rules for auto deduction from braced-init-list |
|||
Allow typename in a template template parameter |
|||
|
__has_cpp_attribute(fallthrough) |
||
|
__has_cpp_attribute(nodiscard) |
||
|
__has_cpp_attribute(maybe_unused) |
||
Extension to aggregate initialization |
__cpp_aggregate_bases >= 201603 |
||
Wording for |
__cpp_constexpr >= 201603 |
||
Unary Folds and Empty Parameter Packs |
__cpp_fold_expressions >= 201603 |
||
Generalizing the Range-Based For Loop |
__cpp_range_based_for >= 201603 |
||
Lambda capture of |
__cpp_capture_star_this >= 201603 |
||
Construction Rules for |
|||
Hexadecimal floating literals for C++ |
3.0 |
__cpp_hex_float >= 201603 |
|
Dynamic memory allocation for over-aligned data |
__cpp_aligned_new >= 201606 |
||
Guaranteed copy elision |
__cpp_guaranteed_copy_elision >= 201606 |
||
Refining Expression Evaluation Order for Idiomatic C++ |
|||
|
__cpp_if_constexpr >= 201606 |
||
Selection statements with initializer |
|||
Template argument deduction for class templates |
|
||
Declaring non-type template parameters with auto |
|
||
Using attribute namespaces without repetition |
|||
Ignoring unsupported non-standard attributes |
Yes |
||
Structured bindings |
__cpp_structured_bindings >= 201606 |
||
Remove Deprecated Use of the |
|||
Remove Deprecated |
|||
Make exception specifications be part of the type system |
__cpp_noexcept_function_type >= 201510 |
||
|
|||
Rewording inheriting constructors (core issue 1941 et al) |
__cpp_inheriting_constructors >= 201511 |
||
Inline variables |
__cpp_inline_variables >= 201606 |
||
DR 150, Matching of template template arguments |
__cpp_template_template_args >= 201611 |
||
Removing dynamic exception specifications |
|||
Pack expansions in using-declarations |
__cpp_variadic_using >= 201611 |
||
A |
Technical Specifications#
GCC also implements experimental support for some language Technical Specifications published by the C++ committee.
Important: Because these Technical Specifications are still evolving toward future inclusion in a C++ standard, GCC’s support is experimental. No attempt will be made to maintain backward compatibility with implementations of features that do not reflect the final standard.
Technical Specification |
Document |
Available in GCC? |
Compiler Option |
SD-6 Feature Test |
---|---|---|---|---|
Concepts |
-fconcepts |
__cpp_concepts >= 201507 |
||
Transactional Memory |
6 (no atomic_cancel) |
-fgnu-tm |
__cpp_transactional_memory >= 201505 |
|
Coroutines |
-fcoroutines |
__cpp_impl_coroutine >= 201902L |
||
Modules |
-fmodules-ts |
__cpp_modules >= 201810L |
C++14 Support in GCC#
GCC has full support for the of the 2014 C++ standard.
This mode is the default in GCC 6.1 up until GCC 10 (including); it can
be explicitly selected with the -std=c++14
command-line flag, or
-std=gnu++14
to enable GNU extensions as well.
C++14 Language Features#
The following table lists new language features that are part of the C++14 standard. The “Proposal” column provides a link to the ISO C++ committee proposal that describes the feature, while the “Available in GCC?” column indicates the first version of GCC that contains an implementation of this feature.
Language Feature |
Proposal |
Available in GCC? |
SD-6 Feature Test |
---|---|---|---|
Tweak to certain C++ contextual conversions |
|||
Binary literals |
__cpp_binary_literals >= 201304 |
||
Return type deduction for normal functions |
__cpp_decltype_auto >= 201304 |
||
Generalized lambda capture (init-capture) |
__cpp_init_captures >= 201304 |
||
Generic (polymorphic) lambda expressions |
__cpp_generic_lambdas >= 201304 |
||
Variable templates |
__cpp_variable_templates >= 201304 |
||
Relaxing requirements on constexpr functions |
__cpp_constexpr >= 201304 |
||
Member initializers and aggregates |
__cpp_aggregate_nsdmi >= 201304 |
||
Clarifying memory allocation |
N/A |
||
Sized deallocation |
__cpp_sized_deallocation >= 201309 |
||
[[deprecated]] attribute |
4.9 (N3797) |
__has_cpp_attribute(deprecated) >= 201309 |
|
Single-quotation-mark as a digit separator |
4.9 (N3797) |
__cpp_digit_separator >= 201309 |
This feature was briefly part of the C++14 working paper, but was not part of the published standard; as a result, it has been removed from the compiler.
C++11 Support in GCC#
GCC 4.8.1 was the first feature-complete implementation of the 2011 C++ standard, previously known as C++0x.
This mode can be selected with the -std=c++11
command-line flag, or
-std=gnu++11
to enable GNU extensions as well.
For information about C++11 support in a specific version of GCC, please see:
Language Feature |
Proposal |
Available in GCC? |
SD-6 Feature Test |
---|---|---|---|
Rvalue references |
__cpp_rvalue_references >= 200610 |
||
Rvalue references for |
__cpp_ref_qualifiers >= 200710 |
||
Initialization of class objects by rvalues |
Yes |
||
Non-static data member initializers |
__cpp_nsdmi >= 200809 |
||
Variadic templates |
__cpp_variadic_templates >= 200704 |
||
Extending variadic template template parameters |
|||
Initializer lists |
__cpp_initializer_lists >= 200806 |
||
Static assertions |
__cpp_static_assert >= 200410 |
||
|
|||
Multi-declarator |
|||
Removal of auto as a storage-class specifier |
|||
New function declarator syntax |
|||
New wording for C++0x lambdas |
__cpp_lambdas >= 200907 |
||
Declared type of an expression |
__cpp_decltype >= 200707 |
||
decltype and call expressions |
|||
Right angle brackets |
|||
Default template arguments for function templates |
|||
Solving the SFINAE problem for expressions |
|||
Template aliases |
__cpp_alias_templates >= 200704 |
||
Extern templates |
Yes |
||
Null pointer constant |
|||
Strongly-typed enums |
|||
Forward declarations for enums |
|||
Generalized attributes |
|
||
Generalized constant expressions |
__cpp_constexpr >= 200704 |
||
Alignment support |
|||
Delegating constructors |
__cpp_delegating_constructors >= 200604 |
||
Inheriting constructors |
__cpp_inheriting_constructors >= 200802 |
||
Explicit conversion operators |
|||
New character types |
__cpp_unicode_characters >= 200704 |
||
Unicode string literals |
__cpp_unicode_literals >= 200710 |
||
Raw string literals |
__cpp_raw_strings >= 200710 |
||
Universal character name literals |
|||
User-defined literals |
__cpp_user_defined_literals >= 200809 |
||
Standard Layout Types |
|||
Defaulted and deleted functions |
|||
Extended friend declarations |
|||
Extending |
|||
Inline namespaces |
|||
Unrestricted unions |
|||
Local and unnamed types as template arguments |
|||
Range-based for |
__cpp_range_based_for >= 200907 |
||
Explicit virtual overrides |
|||
|
No |
||
Allowing move constructors to throw [noexcept] |
|||
Defining move special member functions |
|||
Concurrency |
|||
Sequence points |
Yes |
||
Atomic operations |
|||
Strong Compare and Exchange |
|||
Bidirectional Fences |
|||
Memory model |
|||
Data-dependency ordering: atomics and memory model |
|
||
Propagating exceptions |
|||
Abandoning a process and at_quick_exit |
|||
Allow atomics use in signal handlers |
Yes |
||
Thread-local storage |
|||
Dynamic initialization and destruction with concurrency |
__cpp_threadsafe_static_init >= 200806 |
||
C99 Features in C++11 |
|||
|
|||
C99 preprocessor |
|||
|
|||
Extended integral types |
Yes |
C++98 Support in GCC#
GCC has full support for the 1998 C++ standard as modified by the 2003
technical corrigendum and some later defect reports, excluding the
export
feature which was later removed from the language.
This mode is the default in GCC versions prior to 6.1; it can be
explicitly selected with the -std=c++98
command-line flag, or
-std=gnu++98
to enable GNU extensions as well.
For questions related to the use of GCC, please consult these web pages and the GCC manuals. If that fails, the gcc-help@gcc.gnu.org mailing list might help. Comments on these web pages and the development of GCC are welcome on our developer list at gcc@gcc.gnu.org. All of our lists have public archives. Copyright (C) Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.
These pages are maintained by the GCC team. Last modified 2022-10-21.