[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
Aidan Goldfarb via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 29 12:45:23 PST 2025
================
@@ -11714,13 +11714,37 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
return;
}
- case TemplateDeductionResult::InvalidExplicitArguments:
+ case TemplateDeductionResult::InvalidExplicitArguments: {
assert(ParamD && "no parameter found for invalid explicit arguments");
- if (ParamD->getDeclName())
- S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
- << ParamD->getDeclName();
- else {
+ if (ParamD->getDeclName()) {
----------------
AidanGoldfarb wrote:
Would it be redundant to print the index in all cases, even when we can point to it with SourceRange? Would we prefer a message like:
```
source.cpp:44:5: error: no matching function for call to 'case1'
44 | case1<42>(42);
source.cpp:41:6: note: candidate template ignored: invalid explicitly-specified template argument: expected a type, but got value '42' (of type 'int')
40 | template <typename T>
| ~~~~~~~~~~
41 | void case1(T value) {}
| ^
```
(The above is what I have implemented and am planning to push)
over:
```
source.cpp:44:5: error: no matching function for call to 'case1'
44 | case1<42>(42);
source.cpp:41:6: note: candidate template ignored: invalid explicitly-specified argument for 1st template parameter: expected a type, but got value '42' (of type 'int')
40 | template <typename T>
| ~~~~~~~~~~
41 | void case1(T value) {}
| ^
```
Although perhaps obvious, I am asking because `candidate template ignored: invalid explicitly-specified template argument: expected a type, but got value '42' (of type 'int')` on its own doesn't give us any location information.
https://github.com/llvm/llvm-project/pull/122754
More information about the cfe-commits
mailing list