]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check [[fallthrough]] instead of assuming it when C++17 support is enabled 7574/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 8 Jan 2019 20:25:26 +0000 (21:25 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 8 Jan 2019 20:49:16 +0000 (21:49 +0100)
cmake/checks/check_01_cxx_features.cmake

index 3a71a36a8a2008f9f1428feb9abdca9a2ca7df20..228f858ea3a0af0edeffd77e44bfa9a9ec201f14 100644 (file)
@@ -569,38 +569,61 @@ UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_SAVED
 # but a compiler extension in earlier language versions: check both
 # possibilities here.
 #
-IF(DEAL_II_WITH_CXX17)
+# first try the attribute [[fallthrough]]
+ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wextra ${DEAL_II_CXX_VERSION_FLAG}")
+CHECK_CXX_SOURCE_COMPILES(
+  "
+  int main()
+  {
+    int i = 42;
+    int j = 10;
+    switch(i)
+      {
+      case 1:
+        ++j;
+        [[fallthrough]];
+      case 2:
+        ++j;
+        [[fallthrough]];
+      default:
+        break;
+      }
+   }
+   "
+   DEAL_II_HAVE_CXX17_ATTRIBUTE_FALLTHROUGH
+   )
+
+# see if the current compiler configuration supports the GCC extension
+# __attribute__((fallthrough)) syntax instead
+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_CXX17_ATTRIBUTE_FALLTHROUGH)
   SET(DEAL_II_FALLTHROUGH "[[fallthrough]]")
+ELSEIF(DEAL_II_HAVE_ATTRIBUTE_FALLTHROUGH)
+  SET(DEAL_II_FALLTHROUGH "__attribute__((fallthrough))")
 ELSE()
-  # see if the current compiler configuration supports the GCC extension
-  # __attribute__((fallthrough)) syntax instead
-  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror -Wextra ${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()
+  SET(DEAL_II_FALLTHROUGH " ")
 ENDIF()
 
 ADD_FLAGS(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_VERSION_FLAG}")

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.