https://github.com/localspook created 
https://github.com/llvm/llvm-project/pull/165073

None

>From a65ee6a8b03329397dd2a48da8667a1f3c9b0d0f Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <[email protected]>
Date: Fri, 24 Oct 2025 21:28:21 -0700
Subject: [PATCH] [clang] Diagnose writing out return type in explicit
 instantiation of function that returns `auto`

---
 clang/docs/ReleaseNotes.rst                        |  2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp           | 10 +---------
 clang/test/CXX/temp/temp.spec/temp.explicit/p6.cpp |  9 ++++++++-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index edb872c1f388d..c1eb79fd898bd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -471,6 +471,8 @@ Bug Fixes to C++ Support
 - Fix for clang incorrectly rejecting the default construction of a union with
   nontrivial member when another member has an initializer. (#GH81774)
 - Diagnose unresolved overload sets in non-dependent compound requirements. 
(#GH51246) (#GH97753)
+- Diagnose writing out the return type in an explicit instantiation of a member
+  function template whose return type is deduced. (#GH164398)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 3baa9775a49e4..15b9737a0af5b 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4882,18 +4882,10 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
   // noreturn can't be dependent, so we don't actually need this for them
   // right now.)
   QualType SpecializationType = Specialization->getType();
-  if (!IsAddressOfFunction) {
+  if (!IsAddressOfFunction)
     ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, SpecializationType,
                                           /*AdjustExceptionSpec*/true);
 
-    // Revert placeholder types in the return type back to undeduced types so
-    // that the comparison below compares the declared return types.
-    if (HasDeducedReturnType) {
-      SpecializationType = SubstAutoType(SpecializationType, QualType());
-      ArgFunctionType = SubstAutoType(ArgFunctionType, QualType());
-    }
-  }
-
   // If the requested function type does not match the actual type of the
   // specialization with respect to arguments of compatible pointer to function
   // types, template argument deduction fails.
diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p6.cpp 
b/clang/test/CXX/temp/temp.spec/temp.explicit/p6.cpp
index 0f5db21190525..281ff86e916c1 100644
--- a/clang/test/CXX/temp/temp.spec/temp.explicit/p6.cpp
+++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p6.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 template<class T> class Array { /* ... */ }; 
 template<class T> void sort(Array<T>& v) { }
@@ -34,3 +33,11 @@ template<> struct hash<S> {
     return 0;
   }
 };
+
+struct A {
+  int g();
+  template<typename T> auto f() { return 0; } // expected-note{{candidate 
template ignored: could not match 'auto ()' against 'auto () -> 
decltype(this->g())' (aka 'auto () -> int')}}
+};
+
+template auto A::f<char>();
+template auto A::f<int>() -> decltype(g()); // expected-error{{explicit 
instantiation of 'f' does not refer to a function template, variable template, 
member function, member class, or static data member}}

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

Reply via email to