test_trap.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // testing trap
  7. // this is a compile only test - but since many build systems
  8. // can't handle a compile-only test - make sure it passes trivially.
  9. #include <boost/safe_numerics/exception_policies.hpp>
  10. #include <boost/safe_numerics/safe_integer.hpp>
  11. using namespace boost::safe_numerics;
  12. template <typename T> // T is char, int, etc data type
  13. using safe_t = safe<
  14. T,
  15. native,
  16. loose_trap_policy // use for compiling and running tests
  17. >;
  18. template<typename T, typename U>
  19. void test(){
  20. safe_t<T> t;
  21. safe_t<U> u;
  22. t + u;
  23. t - u;
  24. t * u;
  25. t / u; // could fail regardless of data type
  26. t % u; // could fail regardless of data type
  27. t << u;
  28. t >> u;
  29. t | u;
  30. t & u;
  31. t ^ u;
  32. }
  33. int main(int, char *[]){
  34. test<std::int8_t, std::int8_t>(); // should compile
  35. test<std::int16_t, std::int16_t>(); // should compile
  36. test<std::int32_t, std::int32_t>(); // should fail to compile
  37. test<std::int64_t, std::int64_t>(); // should fail to compile
  38. return 0;
  39. }