[clang] [Clang][Parser] Build up QualifiedTemplateName for typo correction (PR #108148)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 10 23:56:16 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/108148.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+4-1) 
- (modified) clang/test/Parser/cxx1z-class-template-argument-deduction.cpp (+12) 


``````````diff
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'}}
+
+}

``````````

</details>


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


More information about the cfe-commits mailing list