[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

Antonio Frighetto via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 03:19:16 PST 2025


================
@@ -11714,13 +11715,52 @@ 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()) {
+      TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+      std::string ParamName = ParamD->getNameAsString();
+      TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+      if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(ParamD)) {
+        if (TTPD->wasDeclaredWithTypename())
+          S.Diag(Templated->getLocation(),
+                 diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+              << ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+              << "type";
+        else {
+          // TODO write tests for type constrained classes
+          if (auto *constraint = TTPD->getTypeConstraint())
----------------
antoniofrighetto wrote:

```suggestion
          if (TTPD->getTypeConstraint())
```

https://github.com/llvm/llvm-project/pull/122754


More information about the cfe-commits mailing list