1 // Copyright (c) 2012 Robert Ramey
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 // testing trap
8
9 // this is a compile only test - but since many build systems
10 // can't handle a compile-only test - make sure it passes trivially.
11
12 #include <boost/safe_numerics/exception_policies.hpp>
13 #include <boost/safe_numerics/safe_integer.hpp>
14
15 using namespace boost::safe_numerics;
16 template <typename T> // T is char, int, etc data type
17 using safe_t = safe<
18 T,
19 native,
20 loose_trap_policy // use for compiling and running tests
21 >;
22
23 template<typename T, typename U>
test()24 void test(){
25 safe_t<T> t;
26 safe_t<U> u;
27 t + u;
28 t - u;
29 t * u;
30 t / u; // could fail regardless of data type
31 t % u; // could fail regardless of data type
32 t << u;
33 t >> u;
34 t | u;
35 t & u;
36 t ^ u;
37 }
main(int,char * [])38 int main(int, char *[]){
39 test<std::int8_t, std::int8_t>(); // should compile
40 test<std::int16_t, std::int16_t>(); // should compile
41 test<std::int32_t, std::int32_t>(); // should fail to compile
42 test<std::int64_t, std::int64_t>(); // should fail to compile
43 return 0;
44 }
45