The following code fails to compile with gcc-5-20150301, gcc 4.8.4 and 4.9.2 are fine. The command used is simply "gcc test.c" -------------------- #ifndef __has_cpp_attribute // Optional of course. # define __has_cpp_attribute(x) 0 // Compatibility with non-clang compilers. #endif #if __has_cpp_attribute(clang::fallthrough) || (defined(__clang__) && __clang_major__ >= 4 || (__clang_major__ == 3 &&__clang_minor__ >= 3)) # define FALLTHROUGH [[clang::fallthrough]]; #else # define FALLTHROUGH #endif int main() { } -------------------- Error Message is: test.c:5:30: error: missing ')' after "__has_attribute" #if __has_cpp_attribute(clang::fallthrough) || (defined(__clang__) && __clang_major__ >= 4 || (__clang_major__ == 3 &&__clang_minor__ >= 3)) ^ test.c:5:31: error: ':' without preceding '?' #if __has_cpp_attribute(clang::fallthrough) || (defined(__clang__) && __clang_major__ >= 4 || (__clang_major__ == 3 &&__clang_minor__ >= 3)) ^
Why should it? We don't define __clang_major__.
If you want to compile C++ use g++.
1) It simply shouldnt fail. 2) this is a generic header for C and C++. __has_cpp_attribute(clang::fallthrough) should resolve to 0 and not fail. This is a bug in gcc, unless you can explain why it shouldnt resolve to 0.
even "clang test.c" fails. Either rename it to test.cpp or use g++.
Use the proper check if you are want check if you are compiling c++ code first.
(In reply to npl from comment #3) > 1) It simply shouldnt fail. > 2) this is a generic header for C and C++. > > __has_cpp_attribute(clang::fallthrough) should resolve to 0 and not fail. > This is a bug in gcc, unless you can explain why it shouldnt resolve to 0. I think gcc should simply ignore the __has_cpp_attribute macro, unless it does compile C++ code? if I use other names than __has_cpp_attribute it compiles. I will put some C++ guards around this code, but I still think this is a bug? (And I am compiling with Clang 3.4, but this doesnt support the feature check)
Unfortunately https://gcc.gnu.org/ml/gcc-patches/2015-01/msg02357.html hasn't been checked in yet.
This (and the Iso recommendation) doesnt answer the question whether the __has_cpp_attribute macro should be defined for C sources either (it seems illogical to me). Guess its undefined and not a bug, I wont bother you anymore =)