[clang] [Clang][Parser] Build up QualifiedTemplateName for typo correction (PR #108148)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 10 23:55:45 PDT 2024
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/108148
Since #93433, we have switched to `QualifiedTemplateName`s in more situations to preserve sugars in diagnostics. However, there is one missed case in typo correction that might not meet the expectation in `CheckDeductionGuideDeclarator()`.
No release note because I think we should backport it.
Fixes https://github.com/llvm/llvm-project/issues/107887
>From bd6097801e9a822f5b9e49a6f2fb09b999b4a80d Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Wed, 11 Sep 2024 14:28:46 +0800
Subject: [PATCH] [Clang][Parser] Build up QualifiedTemplateName for typo
correction
---
clang/lib/Sema/SemaTemplate.cpp | 5 ++++-
.../cxx1z-class-template-argument-deduction.cpp | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 513f83146fb59e..e58cd7959b9d77 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3567,7 +3567,10 @@ bool Sema::resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name,
if (Corrected && Corrected.getFoundDecl()) {
diagnoseTypo(Corrected, PDiag(diag::err_no_template_suggest)
<< ATN->getDeclName());
- Name = TemplateName(Corrected.getCorrectionDeclAs<TemplateDecl>());
+ Name = Context.getQualifiedTemplateName(
+ /*NNS=*/nullptr, /*TemplateKeyword=*/false,
+ TemplateName(
+ TemplateName(Corrected.getCorrectionDeclAs<TemplateDecl>())));
return false;
}
diff --git a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
index 2dd61baac31b3c..a1594333abae73 100644
--- a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -255,3 +255,15 @@ void f() {
GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
}
}
+
+namespace GH107887 {
+
+namespace a {
+template <class> struct pair; // expected-note 3{{declared here}}
+}
+template <class T2> pair() -> pair<T2>; // expected-error 2{{no template named 'pair'}} \
+ // expected-error {{deduction guide must be declared in the same scope}} \
+ // expected-error {{cannot be deduced}} \
+ // expected-note {{non-deducible template parameter 'T2'}}
+
+}
More information about the cfe-commits
mailing list