[clang] [Clang][Parser] Build up QualifiedTemplateName for typo correction (PR #108148)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 11 08:28:57 PDT 2024
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/108148
>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 1/2] [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'}}
+
+}
>From 4ea01b4f1053c7d9c2c53ef547ee65395786c39b Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Wed, 11 Sep 2024 23:28:23 +0800
Subject: [PATCH 2/2] Fix a copy-pasta
---
clang/lib/Sema/SemaTemplate.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e58cd7959b9d77..e5ea02a919f4eb 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3569,8 +3569,7 @@ bool Sema::resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name,
<< ATN->getDeclName());
Name = Context.getQualifiedTemplateName(
/*NNS=*/nullptr, /*TemplateKeyword=*/false,
- TemplateName(
- TemplateName(Corrected.getCorrectionDeclAs<TemplateDecl>())));
+ TemplateName(Corrected.getCorrectionDeclAs<TemplateDecl>()));
return false;
}
More information about the cfe-commits
mailing list