compile-time test for C++11 support?

Discussion in 'C++' started by Rui Maciel, Jan 5, 2012.

  1. Rui Maciel

    Rui Maciel Guest

    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
     
    Rui Maciel, Jan 5, 2012
    #1
    1. Advertising

  2. On 1/5/2012 11:27 AM, Rui Maciel wrote:
    > 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
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 5, 2012
    #2
    1. Advertising

  3. Rui Maciel

    Marc Guest

    Leigh Johnston wrote:

    > On 05/01/2012 16:27, Rui Maciel wrote:
    >> Does the C++ standard provide a test to check, at compile time, if a
    >> compiler supports the new C++11 standard?

    >
    > 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.
     
    Marc, Jan 5, 2012
    #3
  4. Rui Maciel

    Rui Maciel Guest

    Leigh Johnston wrote:

    > On 05/01/2012 16:27, Rui Maciel wrote:
    >> Does the C++ standard provide a test to check, at compile time, if a
    >> compiler supports the new C++11 standard?

    >
    > 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
     
    Rui Maciel, Jan 5, 2012
    #4
  5. Rui Maciel

    Rui Maciel Guest

    Victor Bazarov wrote:

    > 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
     
    Rui Maciel, Jan 5, 2012
    #5
  6. Rui Maciel

    Rui Maciel Guest

    Leigh Johnston wrote:

    > 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
     
    Rui Maciel, Jan 5, 2012
    #6
  7. Rui Maciel

    Rui Maciel Guest

    Leigh Johnston wrote:

    > 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
     
    Rui Maciel, Jan 5, 2012
    #7
  8. Rui Maciel

    Marc Guest

    Paavo Helde wrote:

    > Marc <> wrote in news:je4nnb$1kg$:
    >
    >> Leigh Johnston wrote:
    >>
    >>> On 05/01/2012 16:27, Rui Maciel wrote:
    >>>> Does the C++ standard provide a test to check, at compile time, if a
    >>>> compiler supports the new C++11 standard?
    >>>
    >>> 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.

    >
    > 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.
     
    Marc, Jan 5, 2012
    #8
  9. Rui Maciel

    Lynn McGuire Guest

    On 1/5/2012 10:27 AM, Rui Maciel wrote:
    > 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


    BTW, you can see the Visual C++ team plans for C++11 at:
    http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx

    Lynn
     
    Lynn McGuire, Jan 5, 2012
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick Zdunic
    Replies:
    0
    Views:
    930
    Nick Zdunic
    Nov 5, 2003
  2. flamesrock
    Replies:
    8
    Views:
    509
    Hendrik van Rooyen
    Nov 24, 2006
  3. Nagaraj
    Replies:
    1
    Views:
    893
    Lionel B
    Mar 1, 2007
  4. Carter
    Replies:
    2
    Views:
    518
    Carter
    Mar 4, 2009
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    730
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page