Bug 65377 - [5.0 Regression] cpp attribute check ala clang fails to compile
Summary: [5.0 Regression] cpp attribute check ala clang fails to compile
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.0
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-10 10:40 UTC by nolange79
Modified: 2015-03-10 11:18 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nolange79 2015-03-10 10:40:26 UTC
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))
                               ^
Comment 1 Marek Polacek 2015-03-10 10:44:12 UTC
Why should it?  We don't define __clang_major__.
Comment 2 Markus Trippelsdorf 2015-03-10 10:46:25 UTC
If you want to compile C++ use g++.
Comment 3 nolange79 2015-03-10 10:52:54 UTC
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.
Comment 4 Markus Trippelsdorf 2015-03-10 10:59:22 UTC
even "clang test.c" fails. Either rename it to test.cpp or use g++.
Comment 5 Andrew Pinski 2015-03-10 11:01:45 UTC
Use the proper check if you are want check if you are compiling c++ code first.
Comment 6 nolange79 2015-03-10 11:02:41 UTC
(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)
Comment 7 Markus Trippelsdorf 2015-03-10 11:07:09 UTC
Unfortunately https://gcc.gnu.org/ml/gcc-patches/2015-01/msg02357.html hasn't
been checked in yet.
Comment 8 nolange79 2015-03-10 11:18:59 UTC
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 =)