Resolving issues related to error policy - first cut. Passes all tests except shift / undefined behavior.

Still needs to be redone - but on the right track.
This commit is contained in:
Robert Ramey
2017-05-25 11:01:24 -07:00
parent 3f228716de
commit e5749b5b4a
18 changed files with 296 additions and 273 deletions

View File

@@ -11,12 +11,12 @@ using namespace boost::numeric; // for safe_literal
// create a type for holding small integers. We "know" that C++
// type promotion rules will work such that addition will never
// overflow. If we change the program to break this, the usage
// of the trap_exception promotion policy will prevent compilation.
// of the no_exceptions_policy will prevent compilation.
using safe_t = safe_signed_range<
-24,
82,
native, // C++ type promotion rules work OK for this example
trap_exception // catch problems at compile time
no_exceptions_policy // catch problems at compile time
>;
int main(int argc, const char * argv[]){
@@ -25,8 +25,8 @@ int main(int argc, const char * argv[]){
// since the sum of x and y wouldn't be in the legal
// range for z.
// const safe_signed_literal<20> x;
const safe_signed_literal<10, native, trap_exception> x; // no problem
const safe_signed_literal<67, native, trap_exception> y;
const safe_signed_literal<10, native, no_exceptions_policy> x; // no problem
const safe_signed_literal<67, native, no_exceptions_policy> y;
const safe_t z = x + y;
std::cout << "x = " << safe_format(x) << std::endl;