[PATCH] D91659: Allow enum typedefs to be referenced with the 'enum' specifier under MSVC compat mode

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 16 11:58:25 PST 2020


rsmith added inline comments.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:15752-15754
+          bool AnonymousEnumEligible = getLangOpts().MSVCCompat &&
+                                       (Kind == TTK_Enum) &&
+                                       Tag->getDeclName().isEmpty();
----------------
shivanshu3 wrote:
> shivanshu3 wrote:
> > rsmith wrote:
> > > In the anonymous union case, we also need to check for qualifiers on the typedef type, and more broadly perhaps we should be using `getAnonDeclWithTypedefName` here too. Presumably the new case should also only apply for `TUK_Reference`.
> > I added a check for TUK_Reference. But I don't fully understand your other comment about checking the qualifiers on the typedef type. Could you please explain a little more?
> @rsmith Since my newest iteration removes the restriction for the enum to be anonymous, I'm guessing I can mark this comment as resolved?
Regarding qualifiers:
```
enum A { e };
typedef const A B;
void f() {
    enum ::B b = e; // OK?
    b = e; // OK?
}
```
MSVC's behavior here is very strange -- they behave exactly as if the `enum` keyword were not present. The first commented line above is accepted, and the second is rejected because we're assigning to an object of type `const A`.

If we want to be compatible with this kind of thing, then I think we need a larger-scale restructuring: `ActOnTag` would need a way to say "no, wait, this isn't a tag at all, use this non-tag type instead". I don't know how common this kind of code is, but perhaps we could instead reject the first line above (because the typedef isn't for *exactly* the enum type).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91659/new/

https://reviews.llvm.org/D91659



More information about the cfe-commits mailing list