Opened 8 years ago
Last modified 8 years ago
#9944 new Bugs
Regression test relies on undefined compiler behavior
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | To Be Determined | Component: | utility |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
libs/utility/numeric_traits_test.cpp generates values complement_traits<Number>::min using a clever recursive template, but that template relies on left-shifting a negative value, and according to the C++11 standard that’s a no-no (“the behavior is undefined”) which means it’s not a constant expression, which means it can’t be calculated at compile time, which means the BOOST_STATIC_ASSERT in line 332 won’t compile, saying “static_assert expression is not an integral constant expression” (I’m using clang++).
The only use for the clever templates, as the comment in the file says, is for "platforms without <limits> support" so my proposed fix is:
#ifndef BOOST_NO_LIMITS template <class Number> struct complement_traits {
BOOST_STATIC_CONSTANT(Number, min = std::numeric_limits<Number>::min()); BOOST_STATIC_CONSTANT(Number, max = std::numeric_limits<Number>::max());
}; #else [SNIP] All of the other template definitions for complement_traits, complement_traits_aux, etc. #endif
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Kim Barrett suggested using boost::integer_traits<Number>::const_min / const_max
It's not entirely clear what this file (numeric_traits_test.cpp) is testing - there is so much template stuff at the top, and then it looks like a lot of the tests are simply verifying that the templates work. There is data sent to std::cout which is perhaps helpful to developers, but not in an automated regression test. It appears the only thing that it tests (from an automated test point of view) is boost::detail::numeric_distance()?
comment:3 by , 8 years ago
Component: | Regression Testing → utility |
---|---|
Owner: | changed from | to
std::numeric_limits<Number>::min() and std::numeric_limits<Number>::max() are not constant expressions unless c++11 is specified, so a better fix is