This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix Sema::ClassifyName so that it classifies EnumConstantDecl as NonType when they are brought into scope via using enum
ClosedPublic

Authored by shafik on Nov 15 2022, 10:07 PM.

Details

Summary

Currently Sema::ClassifyName(...) in some cases when an enumerator is brought into scope via using enum during lookup it can end up being classified as an OverloadSet. It looks like this was never accounted for when using enum support was implemented and we need to add a check to allow an EnumConstantDecl to be classified as NonType even when it is a class member.

This fixes:
https://github.com/llvm/llvm-project/issues/58057
https://github.com/llvm/llvm-project/issues/59014
https://github.com/llvm/llvm-project/issues/54746

Diff Detail

Event Timeline

shafik created this revision.Nov 15 2022, 10:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 10:07 PM
shafik requested review of this revision.Nov 15 2022, 10:07 PM

Thanks, I didn;'t know about ClassifyName, and obviously never hit a need to adjust it. Thanks for fixing.

The comment above says we don't resolve member-access non-overload sets in order to check access. Do we still get that right for, say,

class B {
 enum A {E}; 
 static auto F (B *p) { return p->E;} // ok
};
auto F (B *p) { return p->E; } // not ok

If so, I guess that comment's not right (any more).

Thanks, I didn;'t know about ClassifyName, and obviously never hit a need to adjust it. Thanks for fixing.

The comment above says we don't resolve member-access non-overload sets in order to check access. Do we still get that right for, say,

class B {
 enum A {E}; 
 static auto F (B *p) { return p->E;} // ok
};
auto F (B *p) { return p->E; } // not ok

If so, I guess that comment's not right (any more).

It says we need to defer certain access checks until we know the context as well.

I checked and with this change it gets this case right. So no behavior change there and I ran check-clang as well and that was clean.

shafik added a project: Restricted Project.

Adding some more reviewers to get more eyes who may be familiar with this corner for the code.

aaron.ballman added inline comments.Nov 21 2022, 9:17 AM
clang/lib/Sema/SemaDecl.cpp
1250–1252

This change looks correct to me -- enum constants are class members but are certainly not forming an overload set!

Did you audit the other places we call isCXXClassMember() to ensure they're sensible regarding enum constant declarations?

shafik marked an inline comment as done.Nov 28 2022, 7:05 PM
shafik added inline comments.
clang/lib/Sema/SemaDecl.cpp
1250–1252

I had not but after looking I don't see any other locations that need modifying.

aaron.ballman accepted this revision.Nov 29 2022, 8:00 AM

LGTM! Please add a release note when landing since this fixes open issues.

This revision is now accepted and ready to land.Nov 29 2022, 8:00 AM
shafik updated this revision to Diff 478630.Nov 29 2022, 10:15 AM
shafik marked an inline comment as done.

Add release note.

This revision was landed with ongoing or failed builds.Nov 29 2022, 10:39 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2022, 10:39 AM