https://github.com/abhijeetsharma200 created 
https://github.com/llvm/llvm-project/pull/186634

When an explicit function template specialization is deleted, the overload 
candidate `Fn` may be a non-canonical `FunctionDecl` where `IsDeleted` is not 
set, even though the canonical decl has it set. `isDeletedAsWritten()` reads 
`this` while `isDeleted()` reads `getCanonicalDecl()`, causing the mismatch. 
Fix by using `getCanonicalDecl()` consistently in the diagnostic.               
                                                                                
                                                                                
                                                                                
            
                                                                                
                                                                                
                                                                                
            
Fixes #185693  

>From c1ab56065998187504e674d4cf88e83b811e865c Mon Sep 17 00:00:00 2001
From: Abhijeet Sharma <[email protected]>
Date: Sat, 14 Mar 2026 23:28:39 +0100
Subject: [PATCH] [clang] Fix 'implicitly deleted' diagnostic for explicitly
 deleted function template specializations, fixes #185693

---
 clang/lib/Sema/SemaOverload.cpp                   |  4 +++-
 clang/test/SemaCXX/deleted-template-spec-diag.cpp | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/deleted-template-spec-diag.cpp

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 97018dbe81057..1ca340e8b72c7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12841,7 +12841,9 @@ static void NoteFunctionCandidate(Sema &S, 
OverloadCandidate *Cand,
 
       S.Diag(Fn->getLocation(), diag::note_ovl_candidate_deleted)
           << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << 
FnDesc
-          << (Fn->isDeleted() ? (Fn->isDeletedAsWritten() ? 1 : 2) : 0);
+          << (Fn->isDeleted()
+                  ? (Fn->getCanonicalDecl()->isDeletedAsWritten() ? 1 : 2)
+                  : 0);
       MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
       return;
     }
diff --git a/clang/test/SemaCXX/deleted-template-spec-diag.cpp 
b/clang/test/SemaCXX/deleted-template-spec-diag.cpp
new file mode 100644
index 0000000000000..fe224b83c808d
--- /dev/null
+++ b/clang/test/SemaCXX/deleted-template-spec-diag.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// https://github.com/llvm/llvm-project/issues/185693
+// Explicitly deleted function template specializations were incorrectly
+// reported as "implicitly deleted" in overload resolution diagnostics.
+
+template <typename T> void fred(const T &x);
+template <> void fred(const double &) = delete; // expected-note {{explicitly 
deleted}}
+
+int main() {
+  fred(8.0); // expected-error {{call to deleted function 'fred'}}
+}

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

Reply via email to