From: Marek Polacek Date: Mon, 26 Sep 2016 15:53:28 +0000 (+0000) Subject: c-lex.c (c_common_has_attribute): Handle attribute fallthrough. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c6147dc433015793d92602811e585b83c9018bc2;p=gcc.git c-lex.c (c_common_has_attribute): Handle attribute fallthrough. * c-lex.c (c_common_has_attribute): Handle attribute fallthrough. * system.h: Use __has_attribute to check whether the fallthrough attribute is supported. * g++.dg/cpp1z/feat-cxx1z.C: Test attribute fallthrough. From-SVN: r240499 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9427b506007..f7122e258d1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-09-26 Marek Polacek + + * system.h: Use __has_attribute to check whether the fallthrough + attribute is supported. + 2016-09-26 Marek Polacek * ipa-inline-analysis.c (find_foldable_builtin_expect): Use diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index cd3eeab02bd..6eec8958902 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2016-09-26 Marek Polacek + + * c-lex.c (c_common_has_attribute): Handle attribute fallthrough. + 2016-09-26 Marek Polacek PR c/7652 diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index 829c18b26a4..5c6496ebecf 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -350,7 +350,8 @@ c_common_has_attribute (cpp_reader *pfile) else if (is_attribute_p ("deprecated", attr_name)) result = 201309; else if (is_attribute_p ("maybe_unused", attr_name) - || is_attribute_p ("nodiscard", attr_name)) + || is_attribute_p ("nodiscard", attr_name) + || is_attribute_p ("fallthrough", attr_name)) result = 201603; if (result) attr_name = NULL_TREE; diff --git a/gcc/system.h b/gcc/system.h index 8ca71cf0f0e..0952e4f6e8f 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -746,8 +746,12 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__)) #endif -#if GCC_VERSION >= 7000 -# define gcc_fallthrough() __attribute__((fallthrough)) +#if GCC_VERSION >= 7000 && defined(__has_attribute) +# if __has_attribute(fallthrough) +# define gcc_fallthrough() __attribute__((fallthrough)) +# else +# define gcc_fallthrough() +# endif #else # define gcc_fallthrough() #endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f8567e1a53c..0692c017ef9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-09-26 Marek Polacek + + * g++.dg/cpp1z/feat-cxx1z.C: Test attribute fallthrough. + 2016-09-26 Martin Liska * c-c++-common/ubsan/sanitize-recover-1.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C index 982572e65cc..71c8c7d3768 100644 --- a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C +++ b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C @@ -370,6 +370,12 @@ # error "__has_cpp_attribute(nodiscard) != 201603" # endif +# if ! __has_cpp_attribute(fallthrough) +# error "__has_cpp_attribute(fallthrough)" +# elif __has_cpp_attribute(fallthrough) != 201603 +# error "__has_cpp_attribute(fallthrough) != 201603" +# endif + #else # error "__has_cpp_attribute" #endif