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.


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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to