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

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 15 22:07:54 PST 2022


shafik created this revision.
shafik added reviewers: erichkeane, aaron.ballman, urnathan.
Herald added a project: All.
shafik requested review of this revision.

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


https://reviews.llvm.org/D138091

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/cxx20-using-enum.cpp


Index: clang/test/SemaCXX/cxx20-using-enum.cpp
===================================================================
--- clang/test/SemaCXX/cxx20-using-enum.cpp
+++ clang/test/SemaCXX/cxx20-using-enum.cpp
@@ -240,4 +240,33 @@
 
 } // namespace Thirteen
 
+namespace GH58057 {
+struct Wrap {
+enum Things {
+  Value1,
+  Value2
+};
+};
+
+using enum Wrap::Things;
+
+int f() {
+  return (Value1 | Value2);
+}
+}
+
+namespace GH59014 {
+struct X {
+  enum Masks {Mask = 1,Shift = 0};
+};
+
+void f(int a) {
+  using enum X::Masks;
+
+  auto u = (Mask);
+  auto v = (Mask << Shift);
+  void (~(Mask));
+}
+}
+
 #endif
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1247,7 +1247,8 @@
   // member accesses, as we need to defer certain access checks until we know
   // the context.
   bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.is(tok::l_paren));
-  if (Result.isSingleResult() && !ADL && !FirstDecl->isCXXClassMember())
+  if (Result.isSingleResult() && !ADL &&
+      (!FirstDecl->isCXXClassMember() || isa<EnumConstantDecl>(FirstDecl)))
     return NameClassification::NonType(Result.getRepresentativeDecl());
 
   // Otherwise, this is an overload set that we will need to resolve later.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138091.475683.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221116/00f4948e/attachment-0001.bin>


More information about the cfe-commits mailing list