C++ Standards Support in GCC - GCC 对 C++ 标准的支持

C++ Standards Support in GCC - 2019-2-20

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 this page.

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 GCC's repository 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 FeatureProposalAvailable in GCC?SD-6 Feature Test
Default member initializers for bit-fieldsP0683R18 
Fixing const-qualified pointers to membersP0704R18 
Allow lambda capture [=, this]P0409R28 
__VA_OPT__ for preprocessor comma elisionP0306R4
P1042R1
8 (partial, no #__VA_OPT__ support) 
Designated initializersP0329R48 
Familiar template syntax for generic lambdasP0428R28 
List deduction of vectorP0702R18 
ConceptsP0734R0
P0857R0
P1084R2
P1141R2
TS with -fconcepts 
Range-based for statements with initializerP0614R19 
Simplifying implicit lambda captureP0588R18 
ADL and function templates that are not visibleP0846R09 
const mismatch with defaulted copy constructorP0641R29 
Less eager instantiation of constexpr functionsP0859R05.2 (mostly)
9 (P0859R0)
 
Consistent comparison (operator<=>)P0515R3
P0905R1
P1120R0
No__cpp_impl_three_way_comparison >= 201711
Access checking on specializationsP0692R1Yes 
Default constructible and assignable stateless lambdasP0624R29 
Lambdas in unevaluated contextsP0315R49 
Language support for empty objectsP0840R29 
Relaxing the range-for loop customization point finding rulesP0962R18 
Allow structured bindings to accessible membersP0969R08 
Relaxing the structured bindings customization point finding rulesP0961R18 
Down with typename!P0634R39 
Allow pack expansion in lambda init-captureP0780R29 
Proposed wording for likely and unlikely attributesP0479R59 
Deprecate implicit capture of this via [=]P0806R29 
Class Types in Non-Type Template ParametersP0732R29__cpp_nontype_template_parameter_class >= 201806
Atomic Compare-and-Exchange with Padding BitsP0528R3No (PR 88101) 
Efficient sized delete for variable sized classesP0722R39__cpp_impl_destroying_delete >= 201806
Allowing Virtual Function Calls in Constant ExpressionsP1064R09 
Prohibit aggregates with user-declared constructorsP1008R19 
Support for contract based programming in C++P0542R5
P1289R1
No (PR 88102) 
explicit(bool)P0892R29__cpp_conditional_explicit >= 201806
Signed integers are two's complementP1236R19 
char8_tP0482R69__cpp_char8_t >= 201811
Immediate functions (consteval)P1073R3No 
std::is_constant_evaluatedP0595R29 
Nested inline namespacesP1094R29 
Relaxations of constexpr restrictionsP1002R1
P1327R1
P1330R0
No 
Feature test macrosP0941R24.9 (__cpp_ macros) 
5 (__has_cpp_attribute)
 

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 GCC's repository 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 FeatureProposalAvailable in GCC?SD-6 Feature Test
Removing trigraphsN40865 
u8 character literalsN42676__cpp_unicode_characters >= 201411
Folding expressionsN42956__cpp_fold_expressions >= 201411
Attributes for namespaces and enumeratorsN42664.9 (namespaces) 
6 (enumerators)
__cpp_namespace_attributes >= 201411 
__cpp_enumerator_attributes >= 201411
Nested namespace definitionsN42306__cpp_nested_namespace_definitions >= 201411
Allow constant evaluation for all non-type template argumentsN42686__cpp_nontype_template_args >= 201411
Extending static_assertN39286__cpp_static_assert >= 201411
New Rules for auto deduction from braced-init-listN39225 
Allow typename in a template template parameterN40515 
[[fallthrough]] attributeP0188R17__has_cpp_attribute(fallthrough)
[[nodiscard]] attributeP0189R14.8 ([[gnu::warn_unused_result]])
7 (P0189R1)
__has_cpp_attribute(nodiscard)
[[maybe_unused]] attributeP0212R14.8 ([[gnu::unused]])
7 (P0212R1)
__has_cpp_attribute(maybe_unused)
Extension to aggregate initializationP0017R17__cpp_aggregate_bases >= 201603
Wording for constexpr lambdaP0170R17__cpp_constexpr >= 201603
Unary Folds and Empty Parameter PacksP0036R06__cpp_fold_expressions >= 201603
Generalizing the Range-Based For LoopP0184R06__cpp_range_based_for >= 201603
Lambda capture of *this by ValueP0018R37__cpp_capture_star_this >= 201603
Construction Rules for enum class variablesP0138R27 
Hexadecimal floating literals for C++P0245R13.0__cpp_hex_float >= 201603
Dynamic memory allocation for over-aligned dataP0035R47__cpp_aligned_new >= 201606
Guaranteed copy elisionP0135R17__cpp_guaranteed_copy_elision >= 201606
Refining Expression Evaluation Order for Idiomatic C++P0145R37 
constexpr ifP0292R27__cpp_if_constexpr >= 201606
Selection statements with initializerP0305R17 
Template argument deduction for class templatesP0091R3
P0512R0
7
8
__cpp_deduction_guides >= 201606
__cpp_deduction_guides >= 201611
Declaring non-type template parameters with autoP0127R27__cpp_template_auto >= 201606
__cpp_nontype_template_parameter_auto >= 201606
Using attribute namespaces without repetitionP0028R47 
Ignoring unsupported non-standard attributesP0283R2Yes 
Structured bindingsP0217R37__cpp_structured_bindings >= 201606
Remove Deprecated Use of the register KeywordP0001R17 
Remove Deprecated operator++(bool)P0002R17 
Make exception specifications be part of the type systemP0012R17__cpp_noexcept_function_type >= 201510
__has_include for C++17P0061R15 
Rewording inheriting constructors (core issue 1941 et al)P0136R17__cpp_inheriting_constructors >= 201511
Inline variablesP0386R27__cpp_inline_variables >= 201606
DR 150, Matching of template template argumentsP0522R07__cpp_template_template_args >= 201611
Removing dynamic exception specificationsP0003R57 
Pack expansions in using-declarationsP0195R27__cpp_variadic_using >= 201611
byte type definitionP0298R07 

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 SpecificationDocumentAvailable in GCC?Compiler OptionSD-6 Feature Test
ConceptsN43776-fconcepts__cpp_concepts >= 201507
Transactional MemoryN45146 (no atomic_cancel)-fgnu-tm__cpp_transactional_memory >= 201505
CoroutinesN4649No  
ModulesN4720In progress  

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 FeatureProposalAvailable in GCC?SD-6 Feature Test
Tweak to certain C++ contextual conversionsN33234.9 
Binary literalsN34724.3 (GNU) 
4.9 (N3472)
__cpp_binary_literals >= 201304
Return type deduction for normal functionsN36384.8 (N3386) 
4.9 (N3638)
__cpp_decltype_auto >= 201304
Generalized lambda capture (init-capture)N36484.5 (partial) 
4.9 (N3648)
__cpp_init_captures >= 201304
Generic (polymorphic) lambda expressionsN36494.9__cpp_generic_lambdas >= 201304
Variable templatesN36515__cpp_variable_templates >= 201304
Relaxing requirements on constexpr functionsN36525__cpp_constexpr >= 201304
Member initializers and aggregatesN36535__cpp_aggregate_nsdmi >= 201304
Clarifying memory allocationN3664N/A 
Sized deallocationN37785__cpp_sized_deallocation >= 201309
[[deprecated]] attributeN37604.9 (N3797)__has_cpp_attribute(deprecated) >= 201309
Single-quotation-mark as a digit separatorN37814.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.

Language FeatureProposalAvailable in GCC?SD-6 Feature Test
Runtime-sized arrays with automatic storage duration 
(Removed from the standard)
N3639?.? (GNU VLAs) 
4.9 (N3639) 
5 (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 FeatureProposalAvailable in GCC?SD-6 Feature Test
Rvalue referencesN2118GCC 4.3__cpp_rvalue_references >= 200610
    Rvalue references for *thisN2439GCC 4.8.1__cpp_ref_qualifiers >= 200710
Initialization of class objects by rvaluesN1610Yes 
Non-static data member initializersN2756GCC 4.7__cpp_nsdmi >= 200809
Variadic templatesN2242GCC 4.3__cpp_variadic_templates >= 200704
    Extending variadic template template parametersN2555GCC 4.4 
Initializer listsN2672GCC 4.4__cpp_initializer_lists >= 200806
Static assertionsN1720GCC 4.3__cpp_static_assert >= 200410
auto-typed variablesN1984GCC 4.4 
    Multi-declarator autoN1737GCC 4.4 
    Removal of auto as a storage-class specifierN2546GCC 4.4 
    New function declarator syntaxN2541GCC 4.4 
New wording for C++0x lambdasN2927GCC 4.5__cpp_lambdas >= 200907
Declared type of an expressionN2343GCC 4.3__cpp_decltype >= 200707
    decltype and call expressionsN3276GCC 4.8.1 
Right angle bracketsN1757GCC 4.3 
Default template arguments for function templatesDR226GCC 4.3 
Solving the SFINAE problem for expressionsDR339GCC 4.4 
Template aliasesN2258GCC 4.7__cpp_alias_templates >= 200704
Extern templatesN1987Yes 
Null pointer constantN2431GCC 4.6 
Strongly-typed enumsN2347GCC 4.4 
Forward declarations for enumsN2764GCC 4.6 
Generalized attributesN2761GCC 4.8__cpp_attributes >= 200809;
__has_cpp_attribute(noreturn) >= 200809;
__has_cpp_attribute(carries_dependency) == 0 (not implemented)
Generalized constant expressionsN2235GCC 4.6__cpp_constexpr >= 200704
Alignment supportN2341GCC 4.8 
Delegating constructorsN1986GCC 4.7__cpp_delegating_constructors >= 200604
Inheriting constructorsN2540GCC 4.8__cpp_inheriting_constructors >= 200802
Explicit conversion operatorsN2437GCC 4.5 
New character typesN2249GCC 4.4__cpp_unicode_characters >= 200704
Unicode string literalsN2442GCC 4.5__cpp_unicode_literals >= 200710
Raw string literalsN2442GCC 4.5__cpp_raw_strings >= 200710
Universal character name literalsN2170GCC 4.5 
User-defined literalsN2765GCC 4.7__cpp_user_defined_literals >= 200809
Standard Layout TypesN2342GCC 4.5 
Defaulted and deleted functionsN2346GCC 4.4 
Extended friend declarationsN1791GCC 4.7 
Extending sizeofN2253GCC 4.4 
Inline namespacesN2535GCC 4.4 
Unrestricted unionsN2544GCC 4.6 
Local and unnamed types as template argumentsN2657GCC 4.5 
Range-based forN2930GCC 4.6__cpp_range_based_for >= 200907
Explicit virtual overridesN2928 
N3206 
N3272
GCC 4.7 
Minimal support for garbage collection and reachability-based leak detectionN2670No 
Allowing move constructors to throw [noexcept]N3050GCC 4.6 
Defining move special member functionsN3053GCC 4.6 
Concurrency
Sequence pointsN2239Yes 
Atomic operationsN2427GCC 4.4 
Strong Compare and ExchangeN2748GCC 4.5 
Bidirectional FencesN2752GCC 4.8 
Memory modelN2429GCC 4.8 
Data-dependency ordering: atomics and memory modelN2664GCC 4.4
(memory_order_consume)
 
Propagating exceptionsN2179GCC 4.4 
Abandoning a process and at_quick_exitN2440GCC 4.8 
Allow atomics use in signal handlersN2547Yes 
Thread-local storageN2659GCC 4.8 
Dynamic initialization and destruction with concurrencyN2660GCC 4.3__cpp_threadsafe_static_init >= 200806
C99 Features in C++11
__func__ predefined identifierN2340GCC 4.3 
C99 preprocessorN1653GCC 4.3 
long longN1811GCC 4.3 
Extended integral typesN1988Yes 

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.

转载于:https://www.cnblogs.com/xuyaowen/p/gcc-cxx-support.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值