GCCG with C++11

Martin Sebor msebor@redhat.com
Thu May 28 17:22:00 GMT 2015

On 05/28/2015 10:31 AM, Jonathan Wakely wrote:
> On 28 May 2015 at 16:51, Martin Sebor wrote:
>> The standard specifies that implementations conforming to C++
>> 11 must define the __cplusplus macro to 201103L, and recommends
>> that non-conforming compilers (presumably those that aim to be
>> C++11 conforming but whose support is incomplete) should use
>> a value with at most five decimal digits.
>> C++ 98 defines __cplusplus to 199711L, and C++ 14 to 201402L.
>> With that, the following should cover past and future cases:
>>    #if __cplusplus == 199711L
>>      // C++ 98 conforming implementation
>>    #elif __cplusplus == 201103L
>>      // C++ 11 conforming implementation
>>    #elif __cplusplus == 201402L
>>      // C++ 14 conforming implementation
>>    #elif __cplusplus > 201402L
>>      // future C++ implementation
>>    #elif 0 < __cplusplus && __cplusplus < 100000L
>>      // non-conforming C++ implementation
>>    #else
>>      // not C++ or a non-conforming C++ implementation
>>    #endif
> Until GCC 4.7.0 __cplusplus was always defined to 1, even though C++11
> support in 4.6.4 was OK, and C++98 support was mostly complete.

Those versions would have to be handled under the 0 < __cplusplus
&& __cplusplus < 100000L block by either querying the __GNUC__
macros, along with others like it, and/or some implementation
specific feature test macros(*).

This approach is in line with the recommendation in the footnote
but it highlights the problem of distinguishing between partial
(even mostly complete) support for any of the existing versions
of C++.


[*] The Feature Testing Recommendations For C++ proposal (N4440
being the latest I could find) tries to alleviate it by providing
test macros for individual features. I know Clang implements parts
of it but don't know what its status is in GCC.

More information about the Gcc-help mailing list