MCPcopy Create free account
hub / github.com/dcleblanc/SafeInt / StaticAssertTU

Function StaticAssertTU

Test/ConstExpr.cpp:371–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369
370 template <typename T, typename U>
371 void StaticAssertTU()
372 {
373 // Constructors
374 static_assert(SafeInt<T>(SafeInt<U>(1)), "SafeInt U constr");
375 static_assert(SafeInt<T>((U)1), "U constr");
376
377 // Assignment operators
378 static_assert((SafeInt<T>() = (U)1), "Assignment U");
379 static_assert((SafeInt<T>() = (T)1), "Assignment T");
380 static_assert((SafeInt<T>() = SafeInt<U>(1)), "Assignment SafeInt U");
381 // Next one happens when T == U, so already included
382 // static_assert((SafeInt<T>() = SafeInt<T>(1)), "Assignment SafeInt T");
383
384 // Test the casting operators
385 static_assert((U)(SafeInt<T>((T)1)), "Casting");
386
387 // Modulus
388 static_assert(SafeInt<T>((T)3) % (U)2, "Modulus");
389 static_assert(SafeInt<T>((T)3) % SafeInt<T>(2), "Modulus");
390 static_assert((SafeInt<T>((T)3) %= (U)2), "Modulus");
391 static_assert((SafeInt<T>((T)3) %= SafeInt<U>(2)), "Modulus");
392 static_assert((U)3 % SafeInt<T>(2), "Modulus");
393 static_assert((T)3 % SafeInt<U>(2), "Modulus");
394
395 // Multiplication
396 // Multiplication must either use intrinsics OR constexpr, but not both because the intrinsics aren't marked constexpr
397#if !SAFEINT_USE_INTRINSICS
398 static_assert(SafeInt<T>((T)3) * (U)2, "Multiplication");
399 static_assert(SafeInt<T>((T)3) * SafeInt<T>(2), "Multiplication");
400 static_assert((SafeInt<T>((T)3) *= (U)2), "Multiplication");
401 static_assert((SafeInt<T>((T)3) *= SafeInt<U>(2)), "Multiplication");
402 static_assert((U)3 * SafeInt<T>(2), "Multiplication");
403 static_assert(((T)3 * SafeInt<U>(2)), "Multiplication");
404#endif
405
406 // Division
407 static_assert(SafeInt<T>((T)3) / (U)2, "Division");
408 static_assert(SafeInt<T>((T)3) / SafeInt<T>(2), "Division");
409 static_assert((SafeInt<T>((T)3) /= (U)2), "Division");
410#if SAFEINT_COMPILER != GCC_COMPILER
411 // gcc is not happy with this one
412 static_assert((SafeInt<T>((T)3) /= SafeInt<U>(2)), "Division");
413 static_assert((U)3 / SafeInt<T>(2), "Division");
414#endif
415 static_assert(DivOperator<T,U>(), "Division");
416
417 // Addition
418 static_assert(SafeInt<T>((T)3) + (U)2, "Addition");
419 static_assert(SafeInt<T>((T)3) + SafeInt<T>(2), "Addition");
420 static_assert((SafeInt<T>((T)3) += (U)2), "Addition");
421 static_assert((SafeInt<T>((T)3) += SafeInt<U>(2)), "Addition");
422 static_assert((U)3 + SafeInt<T>(2), "Addition");
423 static_assert(AddOperator<T, U>(), "Addition");
424
425 // Subtraction
426 static_assert(SafeInt<T>((T)3) - (U)2, "Subtraction");
427 static_assert(SafeInt<T>((T)3) - SafeInt<T>(2), "Subtraction");
428 static_assert((SafeInt<T>((T)3) -= (U)2), "Subtraction");

Callers

nothing calls this directly

Calls 6

SafeEqualsFunction · 0.50
SafeNotEqualsFunction · 0.50
SafeGreaterThanFunction · 0.50
SafeGreaterThanEqualsFunction · 0.50
SafeLessThanFunction · 0.50
SafeLessThanEqualsFunction · 0.50

Tested by

no test coverage detected