Skip to content

boost::mpl::integral_c broken in Clang trunk #69

@jyknight

Description

@jyknight

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions