llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Abhijeet (abhijeetsharma200)

<details>
<summary>Changes</summary>

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  

---
Full diff: https://github.com/llvm/llvm-project/pull/186634.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+3-1) 
- (added) clang/test/SemaCXX/deleted-template-spec-diag.cpp (+12) 


``````````diff
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'}}
+}

``````````

</details>


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

Reply via email to