Bug: undefined behavior of constexpr static_cast from int to unscoped enum without fixed type outside range compiles fine on C++17 #50055
Labels
bugzilla
Issues migrated from bugzilla
c++17
clang:diagnostics
New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
confirmed
Verified by a second party
Extended Description
Hi,
The following code is undefined behavior in C++17. And undefined behavior is not allowed in constant expressions - the compiler is required to diagnose it. Adapted from cppreference:
enum foo { a = 0, b = 1 };
constexpr foo x = static_cast(123); // undefined behavior since C++17
However Clang happily compiles this code:
https://godbolt.org/z/bzhWMxqoE
The text was updated successfully, but these errors were encountered: