Skip to content

Commit 8ff0f85

Browse files
committed
Permit compilation with -fno-exceptions.
If one invokes throw_exception by accident, should fail to link.
1 parent 9b4408a commit 8ff0f85

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ target_compile_features(boost_safe_numerics INTERFACE cxx_std_14)
1818
# Compiler settings - special settings for known compilers
1919
#
2020

21+
set(CMAKE_CXX_STANDARD 14)
22+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
23+
set(CMAKE_CXX_EXTENSIONS OFF)
24+
2125
message(STATUS "compiler is ${CMAKE_CXX_COMPILER_ID}" )
2226

2327
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )

include/boost/safe_numerics/exception_policies.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include <boost/mp11.hpp>
11-
11+
#include <boost/config.hpp> // BOOST_NO_EXCEPTIONS
1212
#include "exception.hpp"
1313

1414
namespace boost {
@@ -55,16 +55,20 @@ struct ignore_exception {
5555
constexpr ignore_exception(const safe_numerics_error &, const char * ){}
5656
};
5757

58+
// emit compile time error if this is invoked.
59+
struct trap_exception {};
60+
5861
// If an exceptional condition is detected at runtime throw the exception.
5962
struct throw_exception {
63+
#ifndef BOOST_NO_EXCEPTIONS
6064
throw_exception(const safe_numerics_error & e, const char * message){
6165
throw std::system_error(std::error_code(e), message);
6266
}
67+
#else
68+
trap_exception(const safe_numerics_error & e, const char * message);
69+
#endif
6370
};
6471

65-
// emit compile time error if this is invoked.
66-
struct trap_exception {};
67-
6872
// given an error code - return the action code which it corresponds to.
6973
constexpr safe_numerics_actions
7074
make_safe_numerics_action(const safe_numerics_error & e){

0 commit comments

Comments
 (0)