-
Notifications
You must be signed in to change notification settings - Fork 81
Closed
Description
Clang has recently addressed an issue where it failed to diagnose the UB of casting an out-of-range integer to an enum in a constant expression.
Since undefined behavior is not allowed in a constant expression, Clang now prohibits enum test { zero }; constexpr int g = static_cast<test>(-1);
with "error: constexpr variable 'g' must be initialized by a constant expression; note: integer value -1 is outside the valid range of values [0, 1] for this enumeration type"
This change breaks boost::mpl::integral_c, since it does exactly that. Demonstrated with example, below (and on godbolt)
#include <boost/mpl/integral_c.hpp>
enum test { zero, one };
boost::mpl::integral_c<test, zero> m;
Originally discovered with a program that was using the boost::numeric library, which in turn uses mpl like the above example.
#include <boost/numeric/conversion/udt_builtin_mixture.hpp>
boost::numeric::udt_builtin_mixture<int, int> m;
sjoubert
Metadata
Metadata
Assignees
Labels
No labels