diff --git a/cmake/modules/CheckCXX11Features.cmake b/cmake/modules/CheckCXX11Features.cmake index 78d749c0b290283b5bad30a5f7b405338f425a13..33c3e68a102e358bd82179c44eccb0392ca4011b 100644 --- a/cmake/modules/CheckCXX11Features.cmake +++ b/cmake/modules/CheckCXX11Features.cmake @@ -10,6 +10,7 @@ # HAVE_CONSTEXPR True if constexpr is supported # HAVE_KEYWORD_FINAL True if final is supported. # HAVE_RANGE_BASED_FOR True if range-based for is supported and working. +# HAVE_NOEXCEPT_SPECIFIER True if nonexcept specifier is supported. include(CMakePushCheckState) cmake_push_check_state() @@ -178,4 +179,22 @@ check_cxx_source_compiles(" " HAVE_RANGE_BASED_FOR ) +# nonexcept specifier +check_cxx_source_compiles(" + void func1() noexcept {} + + void func2() noexcept(true) {} + + template <class T> + void func3() noexcept(noexcept(T())) {} + + int main(void) + { + func1(); + func2(); + func3<int>(); + } +" HAVE_NOEXCEPT_SPECIFIER +) + cmake_pop_check_state() diff --git a/config.h.cmake b/config.h.cmake index 78bae4b369fcaded288a95ec46e685fc95677ab3..2d1e314041500b97ed58aec326c0c390b93a04d1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -107,6 +107,9 @@ /* Define to 1 if C++11 constexpr is supported */ #cmakedefine HAVE_CONSTEXPR 1 +/* Define to 1 if C++11 nonexcept specifier is supported */ +#cmakedefine HAVE_NOEXCEPT_SPECIFIER 1 + /* does the compiler support the keyword 'final'? */ #cmakedefine HAVE_KEYWORD_FINAL 1 diff --git a/dune/common/std/CMakeLists.txt b/dune/common/std/CMakeLists.txt index faa037de66f275bdb992d9094057f8bbebe7b46e..ed8bc87506b4293d0277581130ef14357f7541a0 100644 --- a/dune/common/std/CMakeLists.txt +++ b/dune/common/std/CMakeLists.txt @@ -1,6 +1,8 @@ -install(FILES - constexpr.hh - final.hh - type_traits.hh - utility.hh -DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/common/std) +install( + FILES + constexpr.hh + final.hh + noexcept.hh + type_traits.hh + utility.hh + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/common/std) diff --git a/dune/common/std/Makefile.am b/dune/common/std/Makefile.am index a0f89d80324d34c8da8d4364a570a6578b64da05..5c8a4edab5abda36e1b7a8ea176ed4bfc04b1909 100644 --- a/dune/common/std/Makefile.am +++ b/dune/common/std/Makefile.am @@ -2,6 +2,7 @@ stdincludedir = $(includedir)/dune/common/std stdinclude_HEADERS = \ constexpr.hh \ final.hh \ + noexcept.hh \ type_traits.hh \ utility.hh diff --git a/dune/common/std/noexcept.hh b/dune/common/std/noexcept.hh new file mode 100644 index 0000000000000000000000000000000000000000..0181612a8887eaba531d0ae31c50fc219e1191dd --- /dev/null +++ b/dune/common/std/noexcept.hh @@ -0,0 +1,28 @@ +#ifndef DUNE_COMMON_STD_NOEXCEPT_HH +#define DUNE_COMMON_STD_NOEXCEPT_HH + +/** + * \file + * \brief Definition of the DUNE_NOEXCEPT macro + */ + +#if HAVE_NOEXCEPT_SPECIFIER || defined(DOXYGEN) + +/** + * \brief Set method to noexcept if supported by the compiler. + * \code + #include <dune/common/std/noexcept.hh> + * \endcode + * + * This is a preprocessor define which can be used to mark methods as + * noexcept. + * + * \note This does not support the noexcept operator. + */ +#define DUNE_NOEXCEPT noexcept + +#else +#define DUNE_NOEXCEPT +#endif // HAVE_NOEXCEPT_SPECIFIER || defined(DOXYGEN) + +#endif // DUNE_COMMON_STD_NOEXCEPT_HH diff --git a/m4/Makefile.am b/m4/Makefile.am index 4e388cf9cbf843838d0fe79e74206567380e38c4..d11b9c0c159db594013f92a1eca5e1e0b31cf652 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -14,6 +14,7 @@ ALLM4S = \ cxx0x_nullptr.m4 \ cxx11_constexpr.m4 \ cxx11_final.m4 \ + cxx11_noexcept.m4 \ cxx11_range_based_for.m4 \ dune.m4 \ dune_all.m4 \ diff --git a/m4/cxx11_noexcept.m4 b/m4/cxx11_noexcept.m4 new file mode 100644 index 0000000000000000000000000000000000000000..34d7f00e121a8cd9f9e510db10200efe81808b7e --- /dev/null +++ b/m4/cxx11_noexcept.m4 @@ -0,0 +1,34 @@ +# tests for C++11 noexcept specifier support +# this test does not test the noexcept operator +# the associated macro is called HAVE_NOEXCEPT_SPECIFIER + +AC_DEFUN([DUNE_CXX11_NOEXCEPT_SPECIFIER_CHECK],[ + AC_CACHE_CHECK([for C++11 noexcept specifier], + dune_cv_cxx11_noexcept_specifier_support, + [ + AC_REQUIRE([AC_PROG_CXX]) + AC_REQUIRE([CXX11]) + AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [ + void func1() noexcept {} + + void func2() noexcept(true) {} + + template <class T> + void func3() noexcept(noexcept(T())) {} + ],[ + func1(); + func2(); + func3<int>(); + ])], + dune_cv_cxx11_noexcept_specifier_support=yes, + dune_cv_cxx11_noexcept_specifier_support=no) + AC_LANG_POP + ]) + if test "$dune_cv_cxx11_noexcept_specifier_support" = yes; then + AC_DEFINE(HAVE_NOEXCEPT_SPECIFIER, 1, + [Define to 1 if C++11 nonexcept specifier is supported]) + fi +]) diff --git a/m4/dune_common.m4 b/m4/dune_common.m4 index b0f0ecfc1cfdf4758899d5ef9b65503f18a528ac..9bac85e67593b09bd2a5e65000320827481c76a8 100644 --- a/m4/dune_common.m4 +++ b/m4/dune_common.m4 @@ -21,6 +21,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS], AC_REQUIRE([CXX11]) AC_REQUIRE([NULLPTR_CHECK]) AC_REQUIRE([CXX11_CONSTEXPR_CHECK]) + AC_REQUIRE([DUNE_CXX11_NOEXCEPT_SPECIFIER_CHECK]) AC_REQUIRE([DUNE_CXX11_RANGE_BASED_FOR]) AC_REQUIRE([DUNE_BOOST_BASE]) AC_REQUIRE([DUNE_LINKCXX])