[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

Krystian Stasiowski via cfe-commits cfe-commits at lists.llvm.org
Wed May 8 12:29:21 PDT 2024


https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/91503

>From fd4172e64384379a7c976c4ce597eac629bc111f Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Wed, 8 May 2024 12:59:24 -0400
Subject: [PATCH 1/3] [Clang][Sema] Fix lookup of dependent operator= named by
 using-declaration

---
 clang/lib/Sema/SemaDeclCXX.cpp | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 157d42c09cfcd..91c83564b567e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12963,14 +12963,15 @@ NamedDecl *Sema::BuildUsingDeclaration(
     return nullptr;
   }
 
-  DeclContext *LookupContext = computeDeclContext(SS);
   NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
-  if (!LookupContext || EllipsisLoc.isValid()) {
-    NamedDecl *D;
+  DeclContext *LookupContext = computeDeclContext(SS);
+
+  auto BuildDependent = [&] {
+    NamedDecl *D = nullptr;
     // Dependent scope, or an unexpanded pack
     if (!LookupContext && CheckUsingDeclQualifier(UsingLoc, HasTypenameKeyword,
                                                   SS, NameInfo, IdentLoc))
-      return nullptr;
+      return D;
 
     if (HasTypenameKeyword) {
       // FIXME: not all declaration name kinds are legal here
@@ -12987,7 +12988,7 @@ NamedDecl *Sema::BuildUsingDeclaration(
     CurContext->addDecl(D);
     ProcessDeclAttributeList(S, D, AttrList);
     return D;
-  }
+  };
 
   auto Build = [&](bool Invalid) {
     UsingDecl *UD =
@@ -13002,6 +13003,9 @@ NamedDecl *Sema::BuildUsingDeclaration(
   auto BuildInvalid = [&]{ return Build(true); };
   auto BuildValid = [&]{ return Build(false); };
 
+  if (!LookupContext || EllipsisLoc.isValid())
+    return BuildDependent();
+
   if (RequireCompleteDeclContext(SS, LookupContext))
     return BuildInvalid();
 
@@ -13024,6 +13028,9 @@ NamedDecl *Sema::BuildUsingDeclaration(
 
   LookupQualifiedName(R, LookupContext);
 
+  if (R.wasNotFoundInCurrentInstantiation())
+    return BuildDependent();
+
   // Validate the context, now we have a lookup
   if (CheckUsingDeclQualifier(UsingLoc, HasTypenameKeyword, SS, NameInfo,
                               IdentLoc, &R))

>From 73b26b8b9695a1a4aa52aff14ed8bbf7509253b7 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Wed, 8 May 2024 15:25:30 -0400
Subject: [PATCH 2/3] [FOLD] update test

---
 .../basic.lookup/basic.lookup.qual/class.qual/p2.cpp     | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp b/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
index be07ab0a48b33..2a6bebb27bbeb 100644
--- a/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
+++ b/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}}
                  // expected-note at -15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template<typename T>
   struct S : T {
-    struct U : S { // expected-note 6{{candidate}}
+    // FIXME: S is incomplete here and we should diagnose this!
+    struct U : S {
       using S::S;
     };
     using T::T;
   };
-  S<A>::U ua(0); // expected-error {{no match}}
-  S<B>::U ub(0); // expected-error {{no match}}
+  S<A>::U ua(0);
+  S<B>::U ub(0);
 
   template<typename T>
   struct X : T {

>From 261644c67d97fe14b75300ca9b352c62ad86a212 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Wed, 8 May 2024 15:29:10 -0400
Subject: [PATCH 3/3] [FOLD] add test

---
 .../CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
index 46dd52f8c4c13..cb56699ec4544 100644
--- a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
@@ -471,6 +471,19 @@ namespace N3 {
       this->C::operator=(*this);
     }
   };
+
+  template<typename T>
+  struct E {
+    E& operator=(T);
+    struct F;
+  };
+
+  template<typename T>
+  struct E<T>::F : E<T> {
+    using E::operator=;
+  };
+
+  template struct E<int>;
 } // namespace N3
 
 namespace N4 {



More information about the cfe-commits mailing list