From: David Wells <wellsd2@rpi.edu>
Date: Fri, 7 Jul 2017 19:23:41 +0000 (-0400)
Subject: Add a more general fallthrough attribute.
X-Git-Tag: v9.0.0-rc1~1444^2
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99dbf3562d38c98182622ca11b4fa850cee1a9be;p=dealii.git

Add a more general fallthrough attribute.

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.
---

diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake
index e08dc3c834..d5e3b15e3c 100644
--- a/cmake/checks/check_01_cxx_features.cmake
+++ b/cmake/checks/check_01_cxx_features.cmake
@@ -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()