compile-time test for C++11 support?

R

Rui Maciel

Does the C++ standard provide a test to check, at compile time, if a
compiler supports the new C++11 standard?


Thanks in advance,
Rui Maciel
 
V

Victor Bazarov

Does the C++ standard provide a test to check, at compile time, if a
compiler supports the new C++11 standard?

According to the latest Draft I have:

<<__cplusplus
The name __cplusplus is defined to the value 201103L when compiling a
C++ translation unit.160
---
160) It is intended that future versions of this standard will replace
the value of this macro with a greater value. Non-conforming compilers
should use a value with at most five decimal digits.>>

So, check the value of __cplusplus macro.

V
 
M

Marc

Leigh said:
From the Draft:
"__cplusplus
The name __cplusplus is defined to the value 201103L when compiling a
C++ translation unit."

Sadly, most implementers thought: "cool, that's the easiest feature of
C++11 to implement, let's start with this one" (I am barely
exagerating), thus making it worthless. It does at least show that the
compiler is trying to support parts of C++11.
 
R

Rui Maciel

Leigh said:
From the Draft:
"__cplusplus
The name __cplusplus is defined to the value 201103L when compiling a
C++ translation unit."

However I am unsure if there are currently any C++ compilers out in the
wild that actually support *all* of the C++11 standard.

Thanks for the help. It appears to be exactly what I was looking for.
Kudos!

Regarding the comment on the extent the new C++11 standard is supported,
this problem would be solved, or in the very least mitigated, if the C++
standard committee had divided the C++ standard into independent parts,
which then could be individually covered by a dedicated standard that could
be updated independently as needed. This is already done in fundamental
international standards that cover subjects which are a bit more valuable to
society than programming languages, and they work quite well.

But hey, such is life.


Rui Maciel
 
R

Rui Maciel

Victor said:
According to the latest Draft I have:

<<__cplusplus
The name __cplusplus is defined to the value 201103L when compiling a
C++ translation unit.160
---
160) It is intended that future versions of this standard will replace
the value of this macro with a greater value. Non-conforming compilers
should use a value with at most five decimal digits.>>

So, check the value of __cplusplus macro.

Nice. Thanks for the help. Kudos!


Rui Maciel
 
R

Rui Maciel

Leigh said:
From the Draft:
"__cplusplus
The name __cplusplus is defined to the value 201103L when compiling a
C++ translation unit."

After checking a draft of the C++11 standard, I noticed that there is a note
referenced in the __cplusplus macro that states the following:

<quote>
155) It is intended that future versions of this standard will replace the
value of this macro with a greater value. Non-conforming
compilers should use a value with at most five decimal digits.
</quote>

The bit about "non-conforming compilers should use a value with at most five
decimal digits" isn't very clear to me. For example, consider a compiler
which complies with C++98 but only complies with a subset of C++11. In that
case, what value should be assigned to the __cplusplus macro?


Thanks for the help,
Rui Maciel
 
R

Rui Maciel

Leigh said:
It would be implementation defined I guess.

Meanwhile I've discovered that GCC fails to correctly define the __cplusplus
macro. A bug report has been filed over 10 years ago, and it appears to
have been fixed last October. Here is a link to the bug report page:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773


According to the report, this bug has been fixed for GCC 4.7.0, but will not
be backported to older branches.


Rui Maciel
 
M

Marc

Paavo said:
Hmm, MSVC++ 2010 and Comeau 4.3.10.1 have __cplusplus==199711 and gcc 4.3.2
has __cplusplus==1.

Those were out before March 2011, they could hardly guess the value.
Just curious, who are these "most implementers"?

clang is the first I am aware of (they defined it before the standard
was even voted on) and gcc followed suit. clang developers argued that
they were not the first, though I don't know what other implementation
they referred to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top