* C++ PATCH for __has_cpp_attribute and fallthrough
@ 2016-09-26 12:32 Marek Polacek
2016-09-26 15:58 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2016-09-26 12:32 UTC (permalink / raw)
To: GCC Patches; +Cc: Jason Merrill, Jakub Jelinek
This patch updates __has_cpp_attribute for fallthrough, which is now supported.
The system.h hunk should aid people building trunk GCC with older GCC 7 not
supporting this attribute yet.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-09-26 Marek Polacek <polacek@redhat.com>
* 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.
diff --git gcc/c-family/c-lex.c gcc/c-family/c-lex.c
index 829c18b..5c6496e 100644
--- gcc/c-family/c-lex.c
+++ 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 gcc/system.h gcc/system.h
index 8ca71cf..0952e4f 100644
--- gcc/system.h
+++ 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 gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
index 982572e..71c8c7d 100644
--- gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
+++ 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
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for __has_cpp_attribute and fallthrough
2016-09-26 12:32 C++ PATCH for __has_cpp_attribute and fallthrough Marek Polacek
@ 2016-09-26 15:58 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-09-26 15:58 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Jakub Jelinek
OK.
On Mon, Sep 26, 2016 at 8:23 AM, Marek Polacek <polacek@redhat.com> wrote:
> This patch updates __has_cpp_attribute for fallthrough, which is now supported.
>
> The system.h hunk should aid people building trunk GCC with older GCC 7 not
> supporting this attribute yet.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-09-26 Marek Polacek <polacek@redhat.com>
>
> * 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.
>
> diff --git gcc/c-family/c-lex.c gcc/c-family/c-lex.c
> index 829c18b..5c6496e 100644
> --- gcc/c-family/c-lex.c
> +++ 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 gcc/system.h gcc/system.h
> index 8ca71cf..0952e4f 100644
> --- gcc/system.h
> +++ 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 gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
> index 982572e..71c8c7d 100644
> --- gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
> +++ 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
>
> Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-26 15:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-26 12:32 C++ PATCH for __has_cpp_attribute and fallthrough Marek Polacek
2016-09-26 15:58 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).