Skip to content

Bug: undefined behavior of constexpr static_cast from int to unscoped enum without fixed type outside range compiles fine on C++17 #50055

@carlosgalvezp

Description

@carlosgalvezp
Bugzilla Link 50711
Version trunk
OS Linux
CC @zygoloid

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

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillac++17clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions