Value of __cplusplus in GNU modes

Hi,

As of version 4.7, GCC defines __cplusplus to the standard value, even in -std=gnu++98 and -std=gnu++11 modes. Is there any objection to applying the same change to Clang?

Thanks!
Richard

cplusplus-value.diff (2.23 KB)

No objections off-hand, but I wouldn't be surprised if this causes issues with the C headers on a number of systems. Let's try it and evaluate the fallout.

  - Doug

OK, r156113.

Hi,

As of version 4.7, GCC defines __cplusplus to the standard value, even in -std=gnu++98 and -std=gnu++11 modes. Is there any objection to applying the same change to Clang?

No objections off-hand, but I wouldn't be surprised if this causes issues with the C headers on a number of systems. Let's try it and evaluate the fallout.

For many years, it was solaris in particular which was holding up GCC defining the correct value for __cplusplus. This has been fixed in gcc by adding a bunch of 'fix includes'. I don't know exactly what the issues were, or how much clang cares about solaris, but that is probably the best place to check issues.

Chris

When I tried clang TOT (156374) on Solaris 10 I got error which can be shown by the following minimized source:

$ cat -n a.cpp
      1 #include <unistd.h>
      2 #include <stdio.h>
$ ./build-clang/Release/bin/clang++ -c a.cpp
In file included from a.cpp:2:
/usr/include/stdio.h:85:12: error: target of using declaration conflicts with declaration already in scope
using std::rename;
            ^
/usr/include/iso/stdio_iso.h:190:12: note: target of using declaration
extern int rename(const char *, const char *);
                 ^
/usr/include/unistd.h:449:12: note: conflicting declaration
extern int rename(const char *, const char *);
            ^
1 error generated.

This can be minimized even further:

$ cat -n b.cpp
      1 extern "C" {
      2
      3 namespace std {
      4 extern int rename(const char *, const char *);
      5 }
      6
      7 }
      8
      9 using std::rename;
     10
     11 extern "C" {
     12 extern int rename(const char *, const char *);
     13 }
$ ./build-clang/Release/bin/clang++ -c b.cpp
b.cpp:12:12: error: declaration conflicts with target of using declaration already in scope
extern int rename(const char *, const char *);
            ^
b.cpp:4:12: note: target of using declaration
extern int rename(const char *, const char *);
            ^
b.cpp:9:12: note: using declaration
using std::rename;
            ^
1 error generated.

Both g++ 4.7 and Sun C++ 5.11 compile it without errors.
Is it clang bug or other compilers are more liberal.

Definitely a bug.

-Eli

http://llvm.org/bugs/show_bug.cgi?id=12770