[Bug c++/79301] With -Werror=pedantic outside C++17 mode, __has_cpp_attribute(fallthrough) is nonzero but [[fallthrough]] fails
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Feb 8 08:01:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79301
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think right now you need to use
#ifdef __has_cpp_attribute
# if __has_cpp_attribute(fallthrough) >= __cplusplus
[[fallthrough]];
# elif __has_cpp_attribute(gnu::fallthrough)
[[gnu::fallthrough]];
# endif
#endif
(the first #ifdef because __has_cpp_attribute is defined only in recent
compilers, so you'll get errors trying to use it as function-like macro before,
and __has_cpp_attribute should print YYYYMM when the feature has been
introduced which you can compare against __cplusplus).
That said, right now we use the same preprocessor hook for __has_attribute
(which IMNSHO should return non-zero even for __has_attribute(fallthrough)
because you can use __attribute__((fallthrough)), and between
__has_cpp_attribute).
More information about the Gcc-bugs
mailing list