@@ -181,12 +181,22 @@ class MI_EXPORT_LIB Properties {
181181
182182 // Perform a range check just in case
183183 if constexpr (std::is_integral_v<T2> && !std::is_same_v<T2, bool >) {
184- constexpr T2 min = (T2) std::numeric_limits<T>::min (),
185- max = (T2) std::numeric_limits<T>::max ();
186-
187- if (value < min || value > max)
184+ constexpr T min_t = std::numeric_limits<T>::min (),
185+ max_t = std::numeric_limits<T>::max ();
186+ bool out_of_bounds = false ;
187+
188+ if constexpr (std::is_unsigned_v<T>) {
189+ if constexpr (max_t <= (T) std::numeric_limits<T2>::max ())
190+ out_of_bounds = value > (T2) max_t ;
191+ if (value < 0 )
192+ out_of_bounds = true ;
193+ } else {
194+ out_of_bounds = value < (T2) min_t || value > (T2) max_t ;
195+ }
196+
197+ if (out_of_bounds)
188198 Throw (" Property \" %s\" : value %lld is out of bounds, must be "
189- " in the range [%lld, %lld]" , name, value, min, max );
199+ " in the range [%lld, %lld]" , name, value, min_t , max_t );
190200 }
191201
192202 if constexpr (std::is_same_v<T2, ref<Object>>) {
@@ -243,12 +253,23 @@ class MI_EXPORT_LIB Properties {
243253
244254 // Perform a range check just in case
245255 if constexpr (std::is_integral_v<T2> && !std::is_same_v<T2, bool >) {
246- constexpr T2 min = (T2) std::numeric_limits<T>::min (),
247- max = (T2) std::numeric_limits<T>::max ();
256+ constexpr T min_t = std::numeric_limits<T>::min ();
257+ constexpr T max_t = std::numeric_limits<T>::max ();
258+
259+ bool out_of_bounds = false ;
260+
261+ if constexpr (std::is_unsigned_v<T>) {
262+ if constexpr (max_t <= (T) std::numeric_limits<T2>::max ())
263+ out_of_bounds = value > (T2) max_t ;
264+ if (value < 0 )
265+ out_of_bounds = true ;
266+ } else {
267+ out_of_bounds = value < (T2) min_t || value > (T2) max_t ;
268+ }
248269
249- if (value < min || value > max )
270+ if (out_of_bounds )
250271 Throw (" Property \" %s\" : value %lld is out of bounds, must be "
251- " in the range [%lld, %lld]" , name, value, min, max );
272+ " in the range [%lld, %lld]" , name, value, (T2) min_t , (T2) max_t );
252273 }
253274
254275 if constexpr (std::is_same_v<T2, ref<Object>>) {
0 commit comments