From a7de766c55577ba7c755b9b5e88201b5bca0d7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= <gruenich@dune-project.org> Date: Thu, 12 Mar 2020 23:25:07 +0100 Subject: [PATCH] [cmake] Don't check for C++17 features which we require anyway Set the following variables always to 1: DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION DUNE_HAVE_CXX_OPTIONAL DUNE_HAVE_CXX_VARIANT DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR DUNE_HAVE_C_ALIGNED_ALLOC --- cmake/modules/CheckCXXFeatures.cmake | 102 --------------------------- config.h.cmake | 26 +++---- 2 files changed, 11 insertions(+), 117 deletions(-) diff --git a/cmake/modules/CheckCXXFeatures.cmake b/cmake/modules/CheckCXXFeatures.cmake index ba885874d..f0e791bbf 100644 --- a/cmake/modules/CheckCXXFeatures.cmake +++ b/cmake/modules/CheckCXXFeatures.cmake @@ -19,15 +19,6 @@ # :code:`HAS_ATTRIBUTE_DEPRECATED_MSG` # True if attribute deprecated("msg") is supported # -# :code:`DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION` -# True if C++17's class template argument deduction is supported -# -# :code:`DUNE_HAVE_CXX_OPTIONAL` -# True if C++17's optional implementation is supported -# -# :code:`DUNE_HAVE_CXX_VARIANT` -# True if C++17's variant implementation is supported -# # .. cmake_variable:: DISABLE_CXX_VERSION_CHECK # # You may set this variable to TRUE to disable checking for @@ -321,67 +312,6 @@ check_cxx_source_compiles(" " HAVE_IS_INDEXABLE_SUPPORT ) -# support for C++17's class template deduction guides -check_cxx_source_compiles(" - #include <type_traits> - - template<typename T1> - struct A { - A(T1) {} - - template<typename T2> - A(T2, T2) {} - }; - - struct B { - using type = bool; - }; - - template<typename T2> - A(T2, T2) - -> A<typename T2::type>; - - int main() - { - A a1(1); - static_assert(std::is_same_v< decltype(a1), A<int> >); - - B b; - A a2(b, b); - static_assert(std::is_same_v< decltype(a2), A<bool> >); - } -" DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION - ) - - -# support for C++17's optional implementation -check_cxx_source_compiles(" - #include <optional> - #include <string> - - int main() - { - std::optional< std::string > a; - std::string b = a.value_or( \"empty\" ); - } -" DUNE_HAVE_CXX_OPTIONAL - ) - - -# support for C++17's variant implementation -check_cxx_source_compiles(" - #include <variant> - #include <string> - - int main() - { - std::variant< int, std::string > a; - a = \"stringvalue\"; - std::string b = std::get< std::string >(a); - } -" DUNE_HAVE_CXX_VARIANT - ) - # find the threading library if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG) @@ -475,38 +405,6 @@ if(NOT STDTHREAD_WORKS) endif(NOT STDTHREAD_WORKS) -# Check whether we can conditionally throw exceptions in constexpr context to -# signal errors both at compile time and at run time - this does not work in GCC 5 -check_cxx_source_compiles(" - constexpr int foo(int bar) - { - if (bar < 0) - throw bar; - int r = 1; - for (int i = 0 ; i < bar ; ++i) - r += r; - return r; - } - - int main() - { - static_assert(foo(4) == 16, \"test failed\"); - return 0; - } -" DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR - ) - -# Check whether the stadard library supports aligned_alloc() -check_cxx_source_compiles(" - #include <cstdlib> - int main() - { - int* p = static_cast<int*>(aligned_alloc(64, 64*sizeof *p)); - } -" DUNE_HAVE_C_ALIGNED_ALLOC - ) - - # ****************************************************************************** # diff --git a/config.h.cmake b/config.h.cmake index e5b462560..6abb0aea1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -29,21 +29,6 @@ /* does the compiler support __attribute__((unused))? */ #cmakedefine HAS_ATTRIBUTE_UNUSED 1 -/* does the compiler support C++17's class template argument deduction? */ -#cmakedefine DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 - -/* does the compiler support C++17's optional? */ -#cmakedefine DUNE_HAVE_CXX_OPTIONAL 1 - -/* does the compiler support C++17's variant? */ -#cmakedefine DUNE_HAVE_CXX_VARIANT 1 - -/* does the compiler support conditionally throwing exceptions in constexpr context? */ -#cmakedefine DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1 - -/* does the standard library provides aligned_alloc()? */ -#cmakedefine DUNE_HAVE_C_ALIGNED_ALLOC 1 - /* does the standard library provide <experimental/type_traits> ? */ #cmakedefine DUNE_HAVE_HEADER_EXPERIMENTAL_TYPE_TRAITS 1 @@ -135,6 +120,17 @@ /* end private */ + +/* old feature support macros which were tested until 2.7, kept around for one more release */ +/* As these are now always supported due to the new compiler requirements, they are directly */ +/* defined without an explicit test. */ +#define DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 +#define DUNE_HAVE_CXX_OPTIONAL 1 +#define DUNE_HAVE_CXX_VARIANT 1 +#define DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1 +#define DUNE_HAVE_C_ALIGNED_ALLOC 1 + + /* Define to 1 if the compiler properly supports testing for operator[] */ #cmakedefine HAVE_IS_INDEXABLE_SUPPORT 1 -- GitLab