Issue |
142566
|
Summary |
[Clang] Incorrect "Case value is not a constant _expression_"
|
Labels |
clang
|
Assignees |
|
Reporter |
kezyr
|
**Problem:**
Clang (both `clang++` and Clangd) incorrectly produces an error "Case value is not a constant _expression_" when attempting to use a static enumerator (e.g., `State::EnumType::A`) accessed through an instance of its containing struct (`state.A`) within a `switch` statement's `case` label. This should be a valid constant _expression_ according to the C++ standard.
**Expected Behavior:**
The code should compile successfully, as `state.A` refers to the constant enumerator `State::EnumType::A` and is suitable for a `case` label. GCC compiles this code without issues.
**Reproducer Code:**
```c++
struct State {
enum EnumType { A, B };
EnumType value;
constexpr operator EnumType() const noexcept { return value; }
};
struct Foo {
State state;
void workaround() {
auto stateCopy = state;
switch (stateCopy) {
case stateCopy.A: // This compiles successfully with Clang.
case stateCopy.B:
break;
}
}
void shouldCompile() {
switch (state) {
case state.A: // Clang error: "Case value is not a constant _expression_ clang(expr_not_cce)"
case state.B:
break;
}
}
};
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs