Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
carlosgalvezp opened this issue Jun 15, 2021 · 4 comments
Assignees
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

Comments

@carlosgalvezp
Copy link
Contributor

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

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 18, 2021

Confirmed; it doesn't look like any major compiler diagnoses this.

@carlosgalvezp
Copy link
Contributor Author

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels Jul 14, 2022
@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2022

@llvm/issue-subscribers-clang-frontend

@shafik shafik self-assigned this Jul 14, 2022
@jyknight
Copy link
Member

jyknight commented Aug 4, 2022

Closed by shafik's commit b364535.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

5 participants