C++ Support in Clang
Last updated: $Date: 2016-07-14 02:14:59 +0200 (jeu. 14 juil. 2016) $
Clang fully implements all published ISO C++ standards including C++11, as well as the upcoming C++14 standard, and some parts of the fledgling C++1z standard, and is considered a production-quality C++ compiler.
The Clang community is continually striving to improve C++ standards compliance between releases by submitting and tracking C++ Defect Reports and implementing resolutions as they become available.
Experimental work is also under way to implement C++ Technical Specifications that will help drive the future of the C++ programming language.
The LLVM bug tracker contains Clang C++ components that track known bugs with Clang's language conformance in each language mode.
C++98 implementation status
Clang implements all of the ISO C++ 1998 standard (including the defects addressed in the ISO C++ 2003 standard) except for export (which was removed in C++11).
C++11 implementation status
Clang 3.3 and later implement all of the ISO C++ 2011 standard. The following table describes the Clang version in which each feature became available.
By default, Clang builds C++ code according to the C++98 standard, with many
C++11 features accepted as extensions. You can use Clang in C++11 mode with the
-std=c++11 option. Clang's C++11 mode can be used
with libc++ or with gcc's libstdc++, but
patches are needed to make libstdc++-4.4
work with Clang in C++11 mode. Patches are also needed to make
libstdc++-4.6
and libstdc++-4.7 work with Clang
releases prior to version 3.2 in C++11 mode.
| Language Feature | C++11 Proposal | Available in Clang? | 
|---|---|---|
| Rvalue references | N2118 | Clang 2.9 | 
| Rvalue references for *this | N2439 | Clang 2.9 | 
| Initialization of class objects by rvalues | N1610 | Clang 2.9 | 
| Non-static data member initializers | N2756 | Clang 3.0 | 
| Variadic templates | N2242 | Clang 2.9 | 
| Extending variadic template template parameters | N2555 | Clang 2.9 | 
| Initializer lists | N2672 | Clang 3.1 | 
| Static assertions | N1720 | Clang 2.9 | 
| auto-typed variables | N1984 | Clang 2.9 | 
| Multi-declarator auto | N1737 | Clang 2.9 | 
| Removal of auto as a storage-class specifier | N2546 | Clang 2.9 | 
| New function declarator syntax | N2541 | Clang 2.9 | 
| Lambda expressions | N2927 | Clang 3.1 | 
| Declared type of an expression | N2343 | Clang 2.9 | 
| Incomplete return types | N3276 | Clang 3.1 | 
| Right angle brackets | N1757 | Clang 2.9 | 
| Default template arguments for function templates | DR226 | Clang 2.9 | 
| Solving the SFINAE problem for expressions | DR339 | Clang 2.9 | 
| Alias templates | N2258 | Clang 3.0 | 
| Extern templates | N1987 | Clang 2.9 | 
| Null pointer constant | N2431 | Clang 3.0 | 
| Strongly-typed enums | N2347 | Clang 2.9 | 
| Forward declarations for enums | N2764 DR1206 | Clang 3.1 | 
| Standardized attribute syntax | N2761 | Clang 3.3 (1) | 
| Generalized constant expressions | N2235 | Clang 3.1 | 
| Alignment support | N2341 | Clang 3.3 | 
| Conditionally-support behavior | N1627 | Clang 2.9 | 
| Changing undefined behavior into diagnosable errors | N1727 | Clang 2.9 | 
| Delegating constructors | N1986 | Clang 3.0 | 
| Inheriting constructors | N2540 | Clang 3.3 | 
| Explicit conversion operators | N2437 | Clang 3.0 | 
| New character types | N2249 | Clang 2.9 | 
| Unicode string literals | N2442 | Clang 3.0 | 
| Raw string literals | N2442 | Clang 3.0 | 
| Universal character names in literals | N2170 | Clang 3.1 | 
| User-defined literals | N2765 | Clang 3.1 | 
| Standard Layout Types | N2342 | Clang 3.0 | 
| Defaulted functions | N2346 | Clang 3.0 | 
| Deleted functions | N2346 | Clang 2.9 | 
| Extended friend declarations | N1791 | Clang 2.9 | 
| Extending sizeof | N2253 DR850 | Clang 3.1 | 
| Inline namespaces | N2535 | Clang 2.9 | 
| Unrestricted unions | N2544 | Clang 3.1 | 
| Local and unnamed types as template arguments | N2657 | Clang 2.9 | 
| Range-based for | N2930 | Clang 3.0 | 
| Explicit virtual overrides | N2928 N3206 N3272 | Clang 3.0 | 
| Minimal support for garbage collection and reachability-based leak detection | N2670 | N/A (2) | 
| Allowing move constructors to throw [noexcept] | N3050 | Clang 3.0 | 
| Defining move special member functions | N3053 | Clang 3.0 | 
| Concurrency | ||
| Sequence points | N2239 | Clang 3.3 | 
| Atomic operations | N2427 | Clang 3.1 | 
| Strong Compare and Exchange | N2748 | Clang 3.1 (3) | 
| Bidirectional Fences | N2752 | Clang 3.1 | 
| Memory model | N2429 | Clang 3.2 | 
| Data-dependency ordering: atomics and memory model | N2664 | Clang 3.2 (4) | 
| Propagating exceptions | N2179 | Clang 2.9 | 
| Allow atomics use in signal handlers | N2547 | Clang 3.1 | 
| Thread-local storage | N2659 | Clang 3.3 (5) | 
| Dynamic initialization and destruction with concurrency | N2660 | Clang 2.9 | 
| C99 Features in C++11 | ||
| __func__predefined identifier | N2340 | Clang 2.9 | 
| C99 preprocessor | N1653 | Clang 2.9 | 
| long long | N1811 | Clang 2.9 | 
| Extended integral types | N1988 | N/A (6) | 
(1): The [[carries_dependency]] attribute
has no effect.
(2): No compiler changes are required for an implementation
such as Clang that does not provide garbage collection.
(3): All compare-exchange operations are emitted as
strong compare-exchanges.
(4): memory_order_consume is lowered to
memory_order_acquire.
(5): thread_local support
requires a C++ runtime library providing __cxa_thread_atexit, such
as libc++abi 3.6 or later,
or libsupc++ 4.8 or later.
(6): No compiler changes are required for an implementation
such as Clang that does not provide any extended integer types.
__int128 is not treated as an extended integer type,
because changing intmax_t would be an ABI-incompatible
change.
C++14 implementation status
Clang 3.4 and later implement all of the Draft International Standard (see most recent publicly available draft) of the upcoming C++14 language standard. The following table describes the Clang version in which each feature became available.
You can use Clang in C++14 mode with the -std=c++14 option
(use -std=c++1y in Clang 3.4 and earlier).
| Language Feature | C++14 Proposal | Available in Clang? | 
|---|---|---|
| Tweak to certain C++ contextual conversions | N3323 | Clang 3.4 | 
| Binary literals | N3472 | Clang 2.9 | 
| decltype(auto) | N3638 | Clang 3.3 | 
| Return type deduction for normal functions | Clang 3.4 | |
| Initialized lambda captures | N3648 | Clang 3.4 | 
| Generic lambdas | N3649 | Clang 3.4 | 
| Variable templates | N3651 | Clang 3.4 | 
| Relaxing requirements on constexpr functions | N3652 | Clang 3.4 | 
| Member initializers and aggregates | N3653 | Clang 3.3 | 
| Clarifying memory allocation | N3664 | Clang 3.4 | 
| [[deprecated]] attribute | N3760 | Clang 3.4 | 
| Single quotation mark as digit separator | N3781 | Clang 3.4 | 
| C++ Sized Deallocation | N3778 | Clang 3.4 (7) | 
(7): In Clang 3.7 and later, sized deallocation is only enabled
if the user passes the -fsized-deallocation flag. The user must
supply definitions of the sized deallocation functions, either by providing them
explicitly or by using a C++ standard library that does. libstdc++
added these functions in version 5.0, and libc++ added them in
version 3.7.
C++1z implementation status
Clang has experimental support for some proposed features of the C++ standard following C++14, provisionally named C++1z. The following table describes which C++1z features have been implemented in Clang and in which Clang version they became available.
Note that support for these features may change or be removed without notice, as the draft C++1z standard evolves.
You can use Clang in C++1z mode with the -std=c++1z option.
| Language Feature | C++1z Proposal | Available in Clang? | 
|---|---|---|
| static_assert with no message | N3928 | Clang 3.5 | 
| Disabling trigraph expansion by default | N4086 | Clang 3.5 | 
| typename in a template template parameter | N4051 | Clang 3.5 | 
| New auto rules for direct-list-initialization | N3922 | Clang 3.8 (8) | 
| Fold expressions | N4295 | Clang 3.6 | 
| P0036R0 | SVN | |
| u8 character literals | N4267 | Clang 3.6 | 
| Nested namespace definition | N4230 | Clang 3.6 | 
| Attributes for namespaces and enumerators | N4266 | Clang 3.6 | 
| Allow constant evaluation for all non-type template arguments | N4268 | Clang 3.6 | 
| Remove deprecated register storage class | P0001R1 | Clang 3.8 | 
| Remove deprecated bool increment | P0002R1 | Clang 3.8 | 
| Make exception specifications part of the type system | P0012R1 | No | 
| __has_include in preprocessor conditionals | P0061R1 | Yes | 
| New specification for inheriting constructors (DR1941 et al) | P0136R1 | SVN (9) | 
| [[fallthrough]] attribute | P0188R1 | SVN | 
| [[nodiscard]] attribute | P0189R1 | SVN | 
| [[maybe_unused]] attribute | P0212R1 | SVN | 
| Aggregate initialization of classes with base classes | P0017R1 | SVN | 
| constexpr lambda expressions | P0170R1 | No | 
| Differing begin and end types in range-based for | P0184R0 | SVN | 
| Lambda capture of *this | P0018R3 | SVN | 
| Direct-list-initialization of enums | P0138R2 | SVN | 
| Hexadecimal floating-point literals | P0245R1 | Yes | 
| Using attribute namespaces without repetition | P0028R4 | SVN | 
| Dynamic memory allocation for over-aligned data | P0035R4 | No | 
| Template argument deduction for class templates | P0091R3 | No | 
| Non-type template parameters with auto type | P0127R2 | No | 
| Guaranteed copy elision | P0135R1 | No | 
| Stricter expression evaluation order | P0145R3 | No | 
| P0400R0 | ||
| Requirement to ignore unknown attributes | P0283R2 | Yes | 
| constexpr if-statements | P0292R2 | SVN | 
| Inline variables | P0386R2 | SVN | 
| Structured bindings | P0217R3 | No | 
| Separate variable and condition for if and switch | P0305R1 | SVN | 
(8): This is a backwards-incompatible change that is applied to
all language versions that allow type deduction from auto
(per the request of the C++ committee).
In Clang 3.7, a warning is emitted for all cases that would change meaning.
(9): This is the resolution to a Defect Report, so is applied
to all language versions supporting inheriting constructors.
Technical specifications and standing documents
ISO C++ also publishes a number of documents describing additional language and library features that are not part of standard C++. The following table describes which language features have been implemented in Clang and in which Clang version they became available:
| Document | Latest draft | Available in Clang? | 
|---|---|---|
| SD-6: SG10 feature test recommendations | SD-6 | Clang 3.4 (N3745) | 
| Clang 3.6 (N4200) | ||
| [TS] Concepts | P0121R0 | No | 
| [TS] Library Fundamentals, Version 1 (invocation type traits) | N4480 | No | 
| [DRAFT TS] Library Fundamentals, Version 2 (source_location) | N4529 | No | 
| [TS] Modules | P0143R2 | No | 
| [TS] Transactional Memory | N4514 | No |