lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master ef02832 5/5: Guard against undefined behavior


From: Greg Chicares
Subject: [lmi-commits] [lmi] master ef02832 5/5: Guard against undefined behavior
Date: Mon, 17 Apr 2017 13:33:49 -0400 (EDT)

branch: master
commit ef028328831a97c6f6b5aa8c762071a667dad07d
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Guard against undefined behavior
---
 bourn_cast.hpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/bourn_cast.hpp b/bourn_cast.hpp
index eed2530..2d5d02f 100644
--- a/bourn_cast.hpp
+++ b/bourn_cast.hpp
@@ -101,6 +101,9 @@ inline To bourn_cast(From from, std::false_type, 
std::true_type)
     using from_traits = std::numeric_limits<From>;
     static_assert(!to_traits::is_integer && from_traits::is_integer, "");
 
+    // If this assertion fails, the comparisons below may be UB.
+    static_assert(from_traits::digits < to_traits::max_exponent, "");
+
     if(from < to_traits::lowest())
         throw std::runtime_error("Cast would transgress lower limit.");
     if(to_traits::max() < from)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]