From: Daniel Arndt Date: Tue, 8 Jan 2019 20:25:26 +0000 (+0100) Subject: Check [[fallthrough]] instead of assuming it when C++17 support is enabled X-Git-Tag: v9.1.0-rc1~457^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad9515bb7b9bfcd01b3e7db3057f92455e2537ec;p=dealii.git Check [[fallthrough]] instead of assuming it when C++17 support is enabled --- diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index 3a71a36a8a..228f858ea3 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -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}")