[clang] 2149914 - [Clang][Parser] Build up QualifiedTemplateName for typo correction (#108148)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 12 01:36:09 PDT 2024
Author: Younan Zhang
Date: 2024-09-12T16:36:06+08:00
New Revision: 2149914ea10c05c17fc6e994af5cc96b6b312f1b
URL: https://github.com/llvm/llvm-project/commit/2149914ea10c05c17fc6e994af5cc96b6b312f1b
DIFF: https://github.com/llvm/llvm-project/commit/2149914ea10c05c17fc6e994af5cc96b6b312f1b.diff
LOG: [Clang][Parser] Build up QualifiedTemplateName for typo correction (#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()`.
Fixes https://github.com/llvm/llvm-project/issues/107887
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 22749e96a7e3d3..d4db877a823ea5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -381,6 +381,7 @@ Bug Fixes to C++ Support
- Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588)
- Fix a crash when using ``source_location`` in the trailing return type of a lambda expression. (#GH67134)
- A follow-up fix was added for (#GH61460), as the previous fix was not entirely correct. (#GH86361)
+- Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 513f83146fb59e..e5ea02a919f4eb 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3567,7 +3567,9 @@ 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(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