[clang] [Clang][Sema] Fix type of enumerators in incomplete enumerations (PR #84068)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 11 09:00:02 PDT 2024
Sirraide wrote:
Regarding #84712: From what I can tell, the behaviour of cases such as
```c++
enum e1 { a };
enum e2 { b = a };
```
has changed between C++11 and C++14 (at least the wording is different starting with C++14; there may be some other section that states the same for C++11, but I couldn’t find one); specifically, C++11’s [[dcl.enum]p5](https://eel.is/c++draft/enum#dcl.enum-5) states that:
> If the underlying type is not fixed, the type of each enumerator is the type
of its initializing value:
> - If an initializer is specified for an enumerator, the initializing value **has the same type as the expression**
and the constant-expression shall be an integral constant expression (5.19)
Whereas in C++14, that same section reads:
> If the underlying type is not fixed, the type of each enumerator prior
to the closing brace is determined as follows:
> - If an initializer is specified for an enumerator, the constant-expression shall be an integral constant
expression (5.20). **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**.
That is, not only is the type of `b` above not `e2` before the closing brace, but it would seem that its type is supposed to be `e1` before C++14, and whatever the underlying type of `e1` is starting with C++14.
https://github.com/llvm/llvm-project/pull/84068
More information about the cfe-commits
mailing list