summaryrefslogtreecommitdiffstats
path: root/mfbt/Attributes.h
diff options
context:
space:
mode:
authortrav90 <travawine@openmailbox.org>2018-03-04 15:17:01 -0600
committertrav90 <travawine@openmailbox.org>2018-03-04 15:17:01 -0600
commita973e506c148589593226c1f0ccfbed59fff8790 (patch)
tree1ac4cd95dd64558b7d5d68d69b33beb564c212ba /mfbt/Attributes.h
parent45378506119d9d2f851856d46ca86652d229b68e (diff)
downloadUXP-a973e506c148589593226c1f0ccfbed59fff8790.tar
UXP-a973e506c148589593226c1f0ccfbed59fff8790.tar.gz
UXP-a973e506c148589593226c1f0ccfbed59fff8790.tar.lz
UXP-a973e506c148589593226c1f0ccfbed59fff8790.tar.xz
UXP-a973e506c148589593226c1f0ccfbed59fff8790.zip
Add MOZ_FALLTHROUGH macro definition for gcc 7 to suppress -Wimplicit-fallthrough warnings
The generic fallback MOZ_FALLTHROUGH definition is insufficient for GCC 7 and above, resulting in build warning spam and --enable-warnings-as-errors builds failing. The check for clang support is changed to use the __has_cpp_attribute macro, which is more robust than checking the __cplusplus version. Also, MOZ_FALLTHROUGH is now only defined in C++ code, since GCC errors out if it encounters a scoped attribute being used with __has_cpp_attribute in C code. No C code uses MOZ_FALLTHROUGH or derivatives at the moment.
Diffstat (limited to 'mfbt/Attributes.h')
-rw-r--r--mfbt/Attributes.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h
index c875e3a8c..a38257969 100644
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -256,6 +256,8 @@
# define MOZ_MUST_USE
#endif
+#ifdef __cplusplus
+
/**
* MOZ_FALLTHROUGH is an annotation to suppress compiler warnings about switch
* cases that fall through without a break or return statement. MOZ_FALLTHROUGH
@@ -282,9 +284,14 @@
* return 5;
* }
*/
-#if defined(__clang__) && __cplusplus >= 201103L
- /* clang's fallthrough annotations are only available starting in C++11. */
+#ifndef __has_cpp_attribute
+# define __has_cpp_attribute(x) 0
+#endif
+
+#if __has_cpp_attribute(clang::fallthrough)
# define MOZ_FALLTHROUGH [[clang::fallthrough]]
+#elif __has_cpp_attribute(gnu::fallthrough)
+# define MOZ_FALLTHROUGH [[gnu::fallthrough]]
#elif defined(_MSC_VER)
/*
* MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
@@ -296,8 +303,6 @@
# define MOZ_FALLTHROUGH /* FALLTHROUGH */
#endif
-#ifdef __cplusplus
-
/*
* The following macros are attributes that support the static analysis plugin
* included with Mozilla, and will be implemented (when such support is enabled)