[clang] [clang]not lookup name containing a dependent type (PR #77587)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 02:39:50 PST 2024


https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/77587

>From f6b9afa26fabb5f9dcea5615c92914bed93ef474 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Wed, 10 Jan 2024 19:27:31 +0800
Subject: [PATCH 1/2] [clang]not lookup name containing a dependent type

Fixes: #77583
bcd51aaaf8bde4b0ae7a4155d9ce3dec78fe2598 fixed part of template instantiation dependent name issues but still missing some cases
This patch want to enhance the dependent name check
---
 clang/lib/Sema/SemaExprMember.cpp          |  3 ++-
 clang/test/SemaCXX/conversion-function.cpp | 14 +++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 2abec3d86a27d9..32998ae60eafe2 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -782,7 +782,8 @@ Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
                                const Scope *S,
                                ActOnMemberAccessExtraArgs *ExtraArgs) {
   if (BaseType->isDependentType() ||
-      (SS.isSet() && isDependentScopeSpecifier(SS)))
+      (SS.isSet() && isDependentScopeSpecifier(SS)) ||
+      NameInfo.getName().isDependentName())
     return ActOnDependentMemberExpr(Base, BaseType,
                                     IsArrow, OpLoc,
                                     SS, TemplateKWLoc, FirstQualifierInScope,
diff --git a/clang/test/SemaCXX/conversion-function.cpp b/clang/test/SemaCXX/conversion-function.cpp
index b6e6142d179066..220ae78f2d8246 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,13 +475,21 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  template<typename T> struct A {
+  struct A1 {
+    operator int();
+  };
+  template<class T> struct C {
+    template <typename U> using Lookup = decltype(T{}.operator U());
+  };
+  C<A1> v{};
+
+  template<typename T> struct A2 {
     operator T();
   };
-  template<typename T> struct B : A<T> {
+  template<typename T> struct B : A2<T> {
     template<typename U> using Lookup = decltype(&B::operator U);
   };
   using Result = B<int>::Lookup<int>;
-  using Result = int (A<int>::*)();
+  using Result = int (A2<int>::*)();
 }
 #endif

>From e48e981d65502948972d091c612ee7a354abb3d0 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Thu, 11 Jan 2024 18:39:31 +0800
Subject: [PATCH 2/2] add release note

---
 clang/docs/ReleaseNotes.rst                |  4 ++-
 clang/test/SemaCXX/conversion-function.cpp | 33 +++++++++++-----------
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f8bbc89d8949..8e403530a19502 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -708,7 +708,9 @@ Bug Fixes in This Version
 - Clang now emits correct source location for code-coverage regions in `if constexpr`
   and `if consteval` branches.
   Fixes (`#54419 <https://github.com/llvm/llvm-project/issues/54419>`_)
-
+- Fix an issue where clang cannot find conversion function with template
+  parameter when instantiation of template class.
+  Fixes (`#77583 <https://github.com/llvm/llvm-project/issues/77583>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/test/SemaCXX/conversion-function.cpp b/clang/test/SemaCXX/conversion-function.cpp
index 220ae78f2d8246..749e2fc1b452b6 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -475,21 +475,22 @@ struct S {
 
 #if __cplusplus >= 201103L
 namespace dependent_conversion_function_id_lookup {
-  struct A1 {
-    operator int();
-  };
-  template<class T> struct C {
-    template <typename U> using Lookup = decltype(T{}.operator U());
-  };
-  C<A1> v{};
-
-  template<typename T> struct A2 {
-    operator T();
-  };
-  template<typename T> struct B : A2<T> {
-    template<typename U> using Lookup = decltype(&B::operator U);
-  };
-  using Result = B<int>::Lookup<int>;
-  using Result = int (A2<int>::*)();
+namespace gh77583 {
+struct A1 {
+  operator int();
+};
+template<class T> struct C {
+  template <typename U> using Lookup = decltype(T{}.operator U());
+};
+C<A1> v{};
+}
+template<typename T> struct A2 {
+  operator T();
+};
+template<typename T> struct B : A2<T> {
+  template<typename U> using Lookup = decltype(&B::operator U);
+};
+using Result = B<int>::Lookup<int>;
+using Result = int (A2<int>::*)();
 }
 #endif



More information about the cfe-commits mailing list