Skip to content

Breakage in Clang trunk #204

@hokein

Description

@hokein

Clang has recently addressed an llvm/llvm-project#50055 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 magic_enum library, since the library internally uses the [-128, 128] default enum value range. Demonstrated with example, below

#include "magic_enum.hpp"                                
                                                                                
enum Color { Red, Black };                                                      
int main(int argc, char* argv[]) {
   Color color = Red;                                                                                                   
   magic_enum::enum_name(color);                                                                                                            
   return 0;                                                                     
}                                                                                                                      

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions