Skip to content
Snippets Groups Projects
Commit 6db0ffcd authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

Introduce macro DUNE_NOEXCEPT.

Macro to use C++11 feature noexcept specifier.
Add test for CMake and autotools.
parent aa61d398
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
# HAS_ATTRIBUTE_DEPRECATED_MSG True if attribute deprecated("msg") is supported
# HAVE_CONSTEXPR True if constexpr is supported
# HAVE_KEYWORD_FINAL True if final is supported.
# HAVE_NOEXCEPT_SPECIFIER True if nonexcept specifier is supported.
include(CMakePushCheckState)
cmake_push_check_state()
......@@ -166,4 +167,22 @@ check_cxx_source_compiles("
" HAVE_KEYWORD_FINAL
)
# 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()
......@@ -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
......
install(FILES
constexpr.hh
final.hh
type_traits.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/common/std)
install(
FILES
constexpr.hh
final.hh
noexcept.hh
type_traits.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/common/std)
......@@ -2,6 +2,7 @@ stdincludedir = $(includedir)/dune/common/std
stdinclude_HEADERS = \
constexpr.hh \
final.hh \
noexcept.hh \
type_traits.hh
EXTRA_DIST = CMakeLists.txt
......
#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
......@@ -14,6 +14,7 @@ ALLM4S = \
cxx0x_nullptr.m4 \
cxx11_constexpr.m4 \
cxx11_final.m4 \
cxx11_noexcept.m4 \
dune.m4 \
dune_all.m4 \
dune_autobuild.m4 \
......
# 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([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
])
......@@ -21,6 +21,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS],
AC_REQUIRE([CXX11])
AC_REQUIRE([NULLPTR_CHECK])
AC_REQUIRE([CXX11_CONSTEXPR_CHECK])
AC_REQUIRE([CXX11_NOEXCEPT_SPECIFIER_CHECK])
AC_REQUIRE([DUNE_BOOST_BASE])
AC_REQUIRE([DUNE_LINKCXX])
AC_REQUIRE([DUNE_CHECKDEPRECATED])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment