https://github.com/firstmoonlight updated 
https://github.com/llvm/llvm-project/pull/190322

>From d45dc81e1e4a45c1d3c2d30888d5dca400013157 Mon Sep 17 00:00:00 2001
From: victorl <[email protected]>
Date: Fri, 3 Apr 2026 16:10:18 +0800
Subject: [PATCH 1/3] [clang][Sema] fix Crash in clang::Sema::ClassifyName when
 calling overloaded using declarations

---
 clang/lib/Sema/SemaDecl.cpp                   | 44 +++++++++++--------
 .../SemaTemplate/lookup-dependent-using.cpp   | 33 ++++++++++++++
 2 files changed, 58 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/SemaTemplate/lookup-dependent-using.cpp

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2951fd09294d8..498bfc25124cf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1156,26 +1156,32 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, 
CXXScopeSpec &SS,
       IsFunctionTemplate = true;
       Template = Context.getOverloadedTemplateName(Result.begin(),
                                                    Result.end());
-    } else if (!Result.empty()) {
-      auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl(
-          *Result.begin(), /*AllowFunctionTemplates=*/true,
-          /*AllowDependent=*/false));
-      IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
-      IsVarTemplate = isa<VarTemplateDecl>(TD);
-
-      UsingShadowDecl *FoundUsingShadow =
-          dyn_cast<UsingShadowDecl>(*Result.begin());
-      assert(!FoundUsingShadow ||
-             TD == cast<TemplateDecl>(FoundUsingShadow->getTargetDecl()));
-      Template = Context.getQualifiedTemplateName(
-          SS.getScopeRep(),
-          /*TemplateKeyword=*/false,
-          FoundUsingShadow ? TemplateName(FoundUsingShadow) : 
TemplateName(TD));
     } else {
-      // All results were non-template functions. This is a function template
-      // name.
-      IsFunctionTemplate = true;
-      Template = Context.getAssumedTemplateName(NameInfo.getName());
+      TemplateDecl *TD = nullptr;
+      if (!Result.empty()) {
+        TD = dyn_cast_or_null<TemplateDecl>(getAsTemplateNameDecl(
+            *Result.begin(), /*AllowFunctionTemplates=*/true,
+            /*AllowDependent=*/false));
+      }
+
+      if (TD) {
+        IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
+        IsVarTemplate = isa<VarTemplateDecl>(TD);
+
+        UsingShadowDecl *FoundUsingShadow =
+            dyn_cast<UsingShadowDecl>(*Result.begin());
+        assert(!FoundUsingShadow ||
+              TD == cast<TemplateDecl>(FoundUsingShadow->getTargetDecl()));
+        Template = Context.getQualifiedTemplateName(
+            SS.getScopeRep(),
+            /*TemplateKeyword=*/false,
+            FoundUsingShadow ? TemplateName(FoundUsingShadow) : 
TemplateName(TD));
+      } else {
+        // All results were non-template functions. This is a function template
+        // name.
+        IsFunctionTemplate = true;
+        Template = Context.getAssumedTemplateName(NameInfo.getName());
+      }
     }
 
     if (IsFunctionTemplate) {
diff --git a/clang/test/SemaTemplate/lookup-dependent-using.cpp 
b/clang/test/SemaTemplate/lookup-dependent-using.cpp
new file mode 100644
index 0000000000000..1dc0ba7ad29f3
--- /dev/null
+++ b/clang/test/SemaTemplate/lookup-dependent-using.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+// This is a regression test that verifies handling a mix of using-declarations
+// from dependent and non-dependent base classes does not cause name lookup
+// to crash when a dependent entity cannot be converted to a TemplateDecl.
+
+template<typename A>
+class X {
+public:
+    template<typename T>
+    void execute(int a) {}
+};
+
+class Y {
+public:
+    void execute(int a) {}
+};
+
+template<typename A>
+class Exec : public X<A>, public Y {
+public:
+    using X<A>::execute;
+    using Y::execute;
+    
+    void validate() {
+        // In C++20 the 'execute' here is followed by '<'.
+        // The lookup result will include an UnresolvedUsingValueDecl (from 
X<A>)
+        // and a UsingShadowDecl (from Y).
+        execute<int>(42); 
+        execute(42);
+    }
+};

>From 107369a5a1b6a2327c37f19deac78efb141de9e8 Mon Sep 17 00:00:00 2001
From: victorl <[email protected]>
Date: Sun, 12 Apr 2026 23:35:33 +0800
Subject: [PATCH 2/3] wrap the test with a namespace whose name is the issue
 number

---
 clang/test/SemaTemplate/lookup-dependent-using.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/test/SemaTemplate/lookup-dependent-using.cpp 
b/clang/test/SemaTemplate/lookup-dependent-using.cpp
index 1dc0ba7ad29f3..accd0757495fa 100644
--- a/clang/test/SemaTemplate/lookup-dependent-using.cpp
+++ b/clang/test/SemaTemplate/lookup-dependent-using.cpp
@@ -5,6 +5,8 @@
 // from dependent and non-dependent base classes does not cause name lookup
 // to crash when a dependent entity cannot be converted to a TemplateDecl.
 
+namespace GH174951 {
+
 template<typename A>
 class X {
 public:
@@ -31,3 +33,5 @@ class Exec : public X<A>, public Y {
         execute(42);
     }
 };
+
+} // namespace GH174951
\ No newline at end of file

>From e9d7301532db6a9e08165c335d754b2ff1b271f1 Mon Sep 17 00:00:00 2001
From: victorl <[email protected]>
Date: Sun, 12 Apr 2026 23:55:05 +0800
Subject: [PATCH 3/3] add an entry to releasenotes.rst

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1ab3aae640607..1896c7ba4602b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -391,6 +391,7 @@ Bug Fixes to C++ Support
 - Fixed an incorrect template argument deduction when matching packs of 
template
   template parameters when one of its parameters is also a pack. (#GH181166)
 - Fixed a crash when a default argument is passed to an explicit object 
parameter. (#GH176639)
+- Fixed a crash when parsing `using` declaration with multiple overloaded 
functions. (#GH174951)
 - Fixed an alias template CTAD crash.
 - Fixed a crash when diagnosing an invalid static member function with an 
explicit object parameter (#GH177741)
 - Fixed a crash when instantiating an invalid out-of-line static data member 
definition in a local class. (#GH176152)
@@ -411,6 +412,7 @@ Bug Fixes to C++ Support
 - Fix an error using an initializer list with array new for a type that is not 
default-constructible. (#GH81157)
 - We no longer consider conversion operators when copy-initializing from the 
same type. This was non
   conforming and could lead to recursive constraint satisfaction checking. 
(#GH149443)
+- 
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to