]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a more general fallthrough attribute. 4583/head
authorDavid Wells <wellsd2@rpi.edu>
Fri, 7 Jul 2017 19:23:41 +0000 (15:23 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Fri, 7 Jul 2017 19:40:48 +0000 (15:40 -0400)
GCC7 raises implicit fallthrough warnings in a lot of places when we
compile without C++17 support. This patch adds a second check for the
GCC extension `__attribute__((fallthrough))` that works in C++11 and
C++14 and fixes these warnings.

cmake/checks/check_01_cxx_features.cmake

index e08dc3c834cb2511d54797141dcf0f1b81cfb0fa..d5e3b15e3c3f90331720a2b1c01a11c1b59eec6f 100644 (file)
@@ -442,12 +442,44 @@ ELSE()
 ENDIF()
 
 #
-# Enable c++17's [[fallthrough]] attribute.
+# Try to enable a fallthrough attribute. This is a language feature in C++17,
+# but a compiler extension in earlier language versions: check both
+# possibilities here.
 #
 IF(DEAL_II_WITH_CXX17)
   SET(DEAL_II_FALLTHROUGH "[[fallthrough]]")
 ELSE()
-  SET(DEAL_II_FALLTHROUGH " ")
+  # see if the current compiler configuration supports the GCC extension
+  # __attribute__((fallthrough)) syntax instead
+  PUSH_CMAKE_REQUIRED("-Werror")
+  PUSH_CMAKE_REQUIRED("-Wextra")
+  PUSH_CMAKE_REQUIRED("${DEAL_II_CXX_VERSION_FLAG}")
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    int main()
+    {
+      int i = 42;
+      int j = 10;
+      switch(i)
+        {
+        case 1:
+          ++j;
+          __attribute__((fallthrough));
+        case 2:
+          ++j;
+          __attribute__((fallthrough));
+        default:
+          break;
+        }
+    }
+    "
+    DEAL_II_HAVE_ATTRIBUTE_FALLTHROUGH)
+  RESET_CMAKE_REQUIRED()
+  IF(DEAL_II_HAVE_ATTRIBUTE_FALLTHROUGH)
+    SET(DEAL_II_FALLTHROUGH "__attribute__((fallthrough))")
+  ELSE()
+    SET(DEAL_II_FALLTHROUGH " ")
+  ENDIF()
 ENDIF()
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.