Re: GCCG with C++11

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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++.

Martin

[*] 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.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4440.html





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux