https://github.com/AaronBallman approved this pull request.

Hmm, the rules are different between C and C++, but I think we may be okay. In 
C++:

https://eel.is/c++draft/enum#dcl.enum-5.sentence-6
Following the closing brace of an enum-specifier, each enumerator has the type 
of its enumeration.

In C23 6.7.3.3p12:
During the processing of each enumeration constant in the enumerator list, the 
type of the enumeration constant shall be: <long list of things>

p15:
The enumeration member type for an enumerated type without fixed underlying 
type upon completion is:
— int if all the values of the enumeration are representable as an int; or,
— the enumerated type.140)

Footnote 140) The integer type selected during processing of the enumerator 
list (before completion) of the enumeration may not be the same as the 
compatible implementation-defined integer type selected for the completed 
enumeration.

So I believe:
```
typedef enum EnumA {
  A
} EnumA;

enum EnumB {
  B,
  B1 = 1,
  B2 = A == B1
};
```
is not an enum compare warning in C++ because `B1` doesn't have an enumeration 
type due to the enumeration not being fully-defined, and is not an enum compare 
warning in C because `A` has type `int` (due to p15) and `B1` has type `int` 
(due to p12).

I think we play a bit fast-and-loose with the way we treat enum constants in C 
in Clang, but that's outside of the scope of this patch. So LGTM aside from 
some tiny nits!

https://github.com/llvm/llvm-project/pull/84068
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to