https://github.com/TilakChad updated 
https://github.com/llvm/llvm-project/pull/124609

>From c865ba50fd3c1a5d427069e29e035c1d6e3d21d3 Mon Sep 17 00:00:00 2001
From: Tilak Chad <tilakchad...@gmail.com>
Date: Fri, 14 Mar 2025 00:44:10 +0545
Subject: [PATCH 1/2] [Clang] Dependent CallExpr having UnresolvedLookupExpr
 are not created inside non-dependent context

---
 clang/lib/Sema/SemaOverload.cpp               | 17 +++++++-
 .../SemaCXX/deduced-return-type-cxx14.cpp     | 42 +++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6ae9c51c06b31..d99657d4d67b9 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14228,9 +14228,24 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, 
Expr *Fn,
     const FunctionDecl *FDecl = Best->Function;
     if (FDecl && FDecl->isTemplateInstantiation() &&
         FDecl->getReturnType()->isUndeducedType()) {
+
+      // Creating dependent CallExpr is not okay if the enclosing context 
itself
+      // is not dependent. This situation notably arises if a non-dependent
+      // member function calls the later-defined overloaded static function.
+      //
+      // For example, in
+      // class A {
+      //    void c() { callee(1); }
+      //    static auto callee(auto x) { }
+      // };
+      //
+      // Here callee(1) is unresolved at the call site, but is not inside a
+      // dependent context. There will be no further attempt to resolve this
+      // call if it is made dependent.
+
       if (const auto *TP =
               FDecl->getTemplateInstantiationPattern(/*ForDefinition=*/false);
-          TP && TP->willHaveBody()) {
+          TP && TP->willHaveBody() && CurContext->isDependentContext()) {
         return CallExpr::Create(Context, Fn, Args, Context.DependentTy,
                                 VK_PRValue, RParenLoc, 
CurFPFeatureOverrides());
       }
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index c33e07088ba32..aa62c4a57a636 100644
--- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -703,6 +703,48 @@ auto f(auto x) { // cxx14-error {{'auto' not allowed in 
function prototype}}
   return f(1) + 1;
 }
 
+namespace GH122892 {
+  struct NonTemplate {
+    void caller() {
+        c1(int{}); // since-cxx20-error {{cannot be used before it is defined}}
+        c2(int{}); // since-cxx14-error {{cannot be used before it is defined}}
+    }
+
+    static auto c1(auto x) { // since-cxx20-note {{declared here}} // 
cxx14-error {{'auto' not allowed in function prototype}}
+    }
+
+    template <typename T>
+    static auto c2(T x) { // since-cxx14-note {{declared here}}
+        return x;
+    }
+  };
+
+  struct FunctionTemplateSpecialized {
+    template <typename T>
+    void specialized(){}
+
+    template <>
+    void specialized<int>() {
+      c1(int{}); // since-cxx20-error {{cannot be used before it is defined}}
+      c2(int{}); // since-cxx14-error {{cannot be used before it is defined}}
+    }
+
+    static auto c1(auto x) { // since-cxx20-note {{declared here}} // 
cxx14-error {{'auto' not allowed in function prototype}}
+    }
+
+    template <typename T>
+    static auto c2(T x) { // since-cxx14-note {{declared here}}
+        return x;
+    }
+  };
+
+  struct MemberInit {
+    int x1 = c1(int{}); // since-cxx20-error {{cannot be used before it is 
defined}}
+
+    static auto c1(auto x) { return x; } // since-cxx20-note {{declared here}} 
// cxx14-error {{'auto' not allowed in function prototype}}
+  };
+
+}
 }
 
 #if __cplusplus >= 202002L

>From 2c2f30b456e5c4f654660217b1ae88344763dc17 Mon Sep 17 00:00:00 2001
From: Tilak Chad <tilakchad...@gmail.com>
Date: Tue, 18 Mar 2025 22:34:33 +0545
Subject: [PATCH 2/2] [Clang] Updated the clang release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f9..ee352771bd38c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1007,6 +1007,7 @@ Bug Fixes to C++ Support
 - Fix type of expression when calling a template which returns an 
``__array_rank`` querying a type depending on a
   template parameter. Now, such expression can be used with ``static_assert`` 
and ``constexpr``. (#GH123498)
 - Correctly determine the implicit constexprness of lambdas in dependent 
contexts. (#GH97958) (#GH114234)
+- Fixed a clang regression on c++20 mode where unresolved dependent call 
expressions were created inside non-dependent context (#GH122892)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to