c-lex.c (c_common_has_attribute): Handle attribute fallthrough.
authorMarek Polacek <polacek@redhat.com>
Mon, 26 Sep 2016 15:53:28 +0000 (15:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 26 Sep 2016 15:53:28 +0000 (15:53 +0000)
* 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

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-lex.c
gcc/system.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C

index 9427b50600776d6d6fc6396a389a14216a2ec00a..f7122e258d1e84989e317098a58607c375b7e7ed 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-26  Marek Polacek  <polacek@redhat.com>
+
+       * system.h: Use __has_attribute to check whether the fallthrough
+       attribute is supported.
+
 2016-09-26  Marek Polacek  <polacek@redhat.com>
 
        * ipa-inline-analysis.c (find_foldable_builtin_expect): Use
index cd3eeab02bdf699e253bc0b2ac759b12d659a6c9..6eec8958902a77b7b3d811cc57c1a2ee387fa233 100644 (file)
@@ -1,3 +1,7 @@
+2016-09-26  Marek Polacek  <polacek@redhat.com>
+
+       * c-lex.c (c_common_has_attribute): Handle attribute fallthrough.
+
 2016-09-26  Marek Polacek  <polacek@redhat.com>
 
        PR c/7652
index 829c18b26a4c4935c8b947dfb32bdc7664f66414..5c6496ebecf83784db4e4c2c3626d2777142a8e3 100644 (file)
@@ -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;
index 8ca71cf0f0e4b15c723aaeec0f45c44ac3a85674..0952e4f6e8f83c606b310bf95cd69a729387b38a 100644 (file)
@@ -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
index f8567e1a53cef0e21bd8a9a7f91dc896090a9980..0692c017ef98d6f3d2c190860a10bff88119cbf2 100644 (file)
@@ -1,3 +1,7 @@
+2016-09-26  Marek Polacek  <polacek@redhat.com>
+
+       * g++.dg/cpp1z/feat-cxx1z.C: Test attribute fallthrough.
+
 2016-09-26  Martin Liska  <mliska@suse.cz>
 
        * c-c++-common/ubsan/sanitize-recover-1.c: New test.
index 982572e65cc500310f012cdeafc60149b37e0153..71c8c7d3768c2beaa92ad77d90ad8903a7c73bb9 100644 (file)
 #    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