Bug 1215411 - Define MOZ_FALLTHROUGH annotation to suppress clang's -Wimplicit-fallthrough warnings. r=botond
authorChris Peterson <cpeterson@mozilla.com>
Sun, 04 Oct 2015 21:03:26 -0700
changeset 268216 b63d88406a53eca74b89cacb257a3d81e780eb7c
parent 268215 7766307e4759809e4a26ea06fab1f8ecf68e3462
child 268217 0386348c69f5fbaaaf34d9fd9edc07be9678f853
push id66743
push usercpeterson@mozilla.com
push dateMon, 19 Oct 2015 02:22:13 +0000
treeherdermozilla-inbound@a5d54cef3b23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1215411
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1215411 - Define MOZ_FALLTHROUGH annotation to suppress clang's -Wimplicit-fallthrough warnings. r=botond
mfbt/Attributes.h
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -331,16 +331,45 @@
  *   MOZ_WARN_UNUSED_RESULT int foo() { return 42; }
  */
 #if defined(__GNUC__) || defined(__clang__)
 #  define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
 #else
 #  define MOZ_WARN_UNUSED_RESULT
 #endif
 
+/**
+ * MOZ_FALLTHROUGH is an annotation to suppress compiler warnings about switch
+ * cases that fall through without a break or return statement. MOZ_FALLTHROUGH
+ * is only needed on cases that have code:
+ *
+ * switch (foo) {
+ *   case 1: // These cases have no code. No fallthrough annotations are needed.
+ *   case 2:
+ *   case 3:
+ *     foo = 4; // This case has code, so a fallthrough annotation is needed:
+ *     MOZ_FALLTHROUGH;
+ *   default:
+ *     return foo;
+ * }
+ */
+#if defined(__clang__) && __cplusplus >= 201103L
+   /* clang's fallthrough annotations are only available starting in C++11. */
+#  define MOZ_FALLTHROUGH [[clang::fallthrough]]
+#elif defined(_MSC_VER)
+   /*
+    * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
+    * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx
+    */
+#  include <sal.h>
+#  define MOZ_FALLTHROUGH __fallthrough
+#else
+#  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)
  * as C++11 attributes. Since such attributes are legal pretty much everywhere
  * and have subtly different semantics depending on their placement, the
  * following is a guide on where to place the attributes.