[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)
Stephan Bergmann via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 3 01:58:56 PST 2024
stbergmann wrote:
This change started to break the following C++26 code:
```
$ cat test.cc
enum E1 { E11 };
enum E2 {
E21 = E11,
E22 = 1,
E23 = E21 + E22
};
```
```
clang++ -std=c++26 -fsyntax-only test.cc
test.cc:5:15: error: invalid arithmetic between different enumeration types ('E1' and 'E2')
5 | E23 = E21 + E22
| ~~~ ^ ~~~
1 error generated.
```
as within the definition of enum `E2` with unfixed underlying type, while the type of `E21` is indeed `E1`, the type of `E22` there is `int` rather than `E2` (see [dcl.enum]/5.1 "If an initializer is specified for an enumerator, the constant-expression shall be an integral constant expression (7.7). If the expression has unscoped enumeration type, the enumerator has the underlying type of that enumeration type, otherwise it has the same type as the expression.")
https://github.com/llvm/llvm-project/pull/81418
More information about the cfe-commits
mailing list