]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check for the ability to call non-constepr functions in constexpr ones 7158/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 6 Sep 2018 19:54:09 +0000 (21:54 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 6 Sep 2018 20:34:29 +0000 (22:34 +0200)
cmake/checks/check_01_cxx_features.cmake
include/deal.II/base/config.h.in
include/deal.II/base/utilities.h

index 9b44082564726a7bc7f188d44ed71ad255c130c7..a9a6ce7ea0af7c29454dcdddbf3619f556e6f761 100644 (file)
@@ -23,6 +23,7 @@
 #
 #   DEAL_II_HAVE_ATTRIBUTE_FALLTHROUGH
 #   DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE
+#   DEAL_II_HAVE_CXX14_CONSTEXPR_CAN_CALL_NONCONSTEXPR
 #   DEAL_II_HAVE_CXX17_SPECIAL_MATH_FUNCTIONS
 #   DEAL_II_HAVE_FP_EXCEPTIONS
 #   DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS
@@ -552,6 +553,7 @@ UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_SAVED
   "${CMAKE_REQUIRED_FLAGS}${DEAL_II_CXX_VERSION_FLAG}${DEAL_II_WITH_CXX14}${DEAL_II_WITH_CXX17}"
   DEAL_II_HAVE_ATTRIBUTE_FALLTHROUGH
   DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE
+  DEAL_II_HAVE_CXX14_CONSTEXPR_CAN_CALL_NONCONSTEXPR
   DEAL_II_HAVE_CXX17_SPECIAL_MATH_FUNCTIONS
   DEAL_II_HAVE_FP_EXCEPTIONS
   DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS
@@ -668,6 +670,33 @@ CHECK_CXX_SOURCE_COMPILES(
   "
   DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS)
 
+#
+# As long as there exists an argument value such that an invocation of the
+# function or constructor could be an evaluated subexpression of a core constant
+# expression, C++14 allows to call non-constexpr functions from constexpr
+# functions. Unfortunately, not all compilers obey the standard in this regard.
+#
+CHECK_CXX_SOURCE_COMPILES(
+  "
+  void bar()
+  {}
+
+  constexpr int
+  foo(const int n)
+  {
+    if(!(n >= 0))
+      bar();
+    return n;
+  }
+
+  int main()
+  {
+    constexpr unsigned int n=foo(1);
+    return n;
+  }
+  "
+  DEAL_II_HAVE_CXX14_CONSTEXPR_CAN_CALL_NONCONSTEXPR)
+
 #
 # Not all compilers with C++17 support include the new special math
 # functions. Check this separately so that we can use C++17 compilers that don't
index af22c185636caac464ad6ab037317a3baf6c0c11..c32f0dd5b7ae7f74ed01f3ce7cb2e8f24692246a 100644 (file)
  */
 
 #cmakedefine DEAL_II_HAVE_CXX11_IS_TRIVIALLY_COPYABLE
+#cmakedefine DEAL_II_HAVE_CXX14_CONSTEXPR_CAN_CALL_NONCONSTEXPR
 #cmakedefine DEAL_II_HAVE_CXX17_SPECIAL_MATH_FUNCTIONS
 #cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS
 #cmakedefine DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS
index 491796bd182b93273b7f24c9e2448309a43c60e6..44d83cd612d58383d9774fca88735d1a76611f33 100644 (file)
@@ -354,7 +354,8 @@ namespace Utilities
   pow(const unsigned int base, const int iexp)
   {
 #ifdef DEAL_II_WITH_CXX14
-#  if defined(DEAL_II_HAVE_BUILTIN_EXPECT) && defined(__INTEL_COMPILER)
+#  ifdef DEAL_II_HAVE_CXX14_CONSTEXPR_CAN_CALL_NONCONSTEXPR
+#    if defined(DEAL_II_HAVE_BUILTIN_EXPECT) && defined(__INTEL_COMPILER)
     if (!(iexp >= 0))
       ::dealii::deal_II_exceptions::internals::issue_error_noreturn(
         ::dealii::deal_II_exceptions::internals::abort_or_throw_on_exception,
@@ -364,8 +365,9 @@ namespace Utilities
         "iexp>=0",
         "ExcMessage(\"The exponent must not be negative!\")",
         ExcMessage("The exponent must not be negative!"));
-#  else
+#    else
     Assert(iexp >= 0, ExcMessage("The exponent must not be negative!"));
+#    endif
 #  endif
 #endif
     // The "exponentiation by squaring" algorithm used below has to be

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.