gcc版本对C++标准的支持
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
gcc版本对C++标准的⽀持
C++ Standards Support in GCC
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 the library implementation, please see .
C++2a Support in GCC
GCC has experimental support for the next revision of the C++ standard, which is expected to be published in 2020.
C++2a features are available as part of "mainline" GCC in the trunk of and will be available in GCC 8 and later. To enable C++2a support, add the command-line parameter -std=c++2a to your g++command line. Or, to enable GNU extensions in addition to C++2a features, add -std=gnu++2a.
Important: Because the ISO C++2a standard is still evolving, GCC's support is experimental. No attempt will be made to maintain backward compatibility with implementations of C++2a features that do not reflect the final standard.
C++2a Language Features
The following table lists new language features that have been accepted into the C++2a 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 [=, this]
__VA_OPT__ for preprocessor comma elision (partial,
no #__VA_OPT__ support)
Designated initializers
Familiar template syntax for generic lambdas
List deduction of vector
Concepts TS with -fconcepts
Range-based for statements with initializer
Simplifying implicit lambda capture
ADL and function templates that are not visible
const mismatch with defaulted copy constructor
Less eager instantiation of constexpr functions 5.2 (mostly) (P0859R0)
Consistent comparison (operator<=>)No __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
Relaxing the structured bindings customization point
Relaxing the structured bindings customization point finding rules
Down with typename!
Allow pack expansion in lambda init-capture 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
Atomic Compare-and-Exchange with Padding Bits No ()
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
Support for contract based programming in C++No ()
explicit(bool)__cpp_conditional_explicit >= 201806 Signed integers are two's complement
char8_t__cpp_char8_t >= 201811
Immediate functions (consteval)No ()
std::is_constant_evaluated
Nested inline namespaces
Relaxations of constexpr restrictions No ()
Feature test macros (__cpp_ macros) (__has_cpp_attribute)
Modules No ()
Coroutines No ()
Parenthesized initialization of aggregates No__cpp_aggregate_paren_init >= 201902 Stronger Unicode requirements No
Structured binding extensions
C++17 Support in GCC
GCC has experimental support for the latest revision of the C++ standard, which was published in 2017.
C++17 features are available as part of "mainline" GCC in the trunk of and in GCC 5 and later. To enable C++17 support, add the command-line parameter -std=c++17 to your g++ command line. Or, to enable GNU extensions in addition to C++17 features, add -
std=gnu++17.
Important: Because the final ISO C++17 standard is still new, GCC's support is experimental. No attempt will be made to maintain backward compatibility with implementations of C++17 features that do not reflect the final standard.
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
u8 character literals__cpp_unicode_characters >= 201411 Folding expressions__cpp_fold_expressions >= 201411
Attributes for namespaces and enumerators (namespaces)
(enumerators)
__cpp_namespace_attributes >= 201411
__cpp_enumerator_attributes >= 201411
Nested namespace definitions __cpp_nested_namespace_definitions >= 201411
Allow constant evaluation for all non-type template
arguments
__cpp_nontype_template_args >= 201411 Extending static_assert__cpp_static_assert >= 201411
New Rules for auto deduction from braced-init-list
Allow typename in a template template parameter
Allow typename in a template template parameter
[[fallthrough]] attribute__has_cpp_attribute(fallthrough)
[[nodiscard]] attribute ([[gnu::warn_unused_result]])
(P0189R1)
__has_cpp_attribute(nodiscard)
[[maybe_unused]] attribute ([[gnu::unused]])
(P0212R1)
__has_cpp_attribute(maybe_unused)
Extension to aggregate initialization__cpp_aggregate_bases >= 201603 Wording for constexpr lambda__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 *this by Value__cpp_capture_star_this >= 201603 Construction Rules for enum class variables
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++
constexpr if__cpp_if_constexpr >= 201606
Selection statements with initializer
Template argument deduction for class templates __cpp_deduction_guides >= 201606 __cpp_deduction_guides >= 201611
Declaring non-type template parameters with auto __cpp_template_auto >= 201606
__cpp_nontype_template_parameter_auto >= 201606
Using attribute namespaces without repetition
Ignoring unsupported non-standard attributes Yes
Structured bindings__cpp_structured_bindings >= 201606 Remove Deprecated Use of the register Keyword
Remove Deprecated operator++(bool)
Make exception specifications be part of the type
system
__cpp_noexcept_function_type >= 201510 __has_include for C++17
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 byte type definition
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 (no atomic_cancel)-fgnu-tm__cpp_transactional_memory >= 201505
Coroutines
Modules
C++14 Support in GCC
GCC has full support for the previous revision of the C++ standard, which was published in 2014.
This mode is the default in GCC 6.1 and above; 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 (GNU)
(N3472)
__cpp_binary_literals >= 201304
Return type deduction for normal functions (N3386)
(N3638)
__cpp_decltype_auto >= 201304
Generalized lambda capture (init-capture) (partial)
(N3648)
__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 (N3797)__has_cpp_attribute(deprecated) >= 201309
Single-quotation-mark as a digit separator (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.
Language Feature Proposal Available in GCC?SD-6 Feature Test
Runtime-sized arrays with automatic storage duration (Removed from the standard)?.? (GNU VLAs)
(N3639)
(GNU VLAs)
__cpp_runtime_arrays >= 198712
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 *this__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
auto-typed variables
Multi-declarator auto
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 __cpp_attributes >= 200809;
__has_cpp_attribute(noreturn) >= 200809; __has_cpp_attribute(carries_dependency) == 0 (not implemented)
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 sizeof
Inline namespaces
Unrestricted unions
Local and unnamed types as template arguments
Range-based for__cpp_range_based_for >= 200907 Explicit virtual overrides
Minimal support for garbage collection and reachability-
based leak detection
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
(memory_order_consume)
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
__func__ predefined identifier
C99 preprocessor
long long
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.。