[clang] 4f8d92f - [clang] Fix the bogus diagnostic introduced by the newly-added UsingTemplate Kind.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 23 01:59:28 PDT 2022


Author: Haojian Wu
Date: 2022-09-23T10:36:55+02:00
New Revision: 4f8d92f1d6bea3bed2dc450ba33efa4a0f5baffb

URL: https://github.com/llvm/llvm-project/commit/4f8d92f1d6bea3bed2dc450ba33efa4a0f5baffb
DIFF: https://github.com/llvm/llvm-project/commit/4f8d92f1d6bea3bed2dc450ba33efa4a0f5baffb.diff

LOG: [clang] Fix the bogus diagnostic introduced by the newly-added UsingTemplate Kind.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D123808

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/CXX/temp/temp.deduct.guide/p3.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index bad298c8c8bc8..2516d18b31c25 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11056,6 +11056,7 @@ void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
 
     // Check that the return type is written as a specialization of
     // the template specified as the deduction-guide's name.
+    // The template name may not be qualified. [temp.deduct.guide]
     ParsedType TrailingReturnType = Chunk.Fun.getTrailingReturnType();
     TypeSourceInfo *TSI = nullptr;
     QualType RetTy = GetTypeFromParser(TrailingReturnType, &TSI);
@@ -11067,9 +11068,13 @@ void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
       TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
       bool TemplateMatches =
           Context.hasSameTemplateName(SpecifiedName, GuidedTemplate);
-      // FIXME: We should consider other template kinds (using, qualified),
-      // otherwise we will emit bogus diagnostics.
-      if (SpecifiedName.getKind() == TemplateName::Template && TemplateMatches)
+      auto TKind = SpecifiedName.getKind();
+      // A Using TemplateName can't actually be valid (either it's qualified, or
+      // we're in the wrong scope). But we have diagnosed these problems
+      // already.
+      bool SimplyWritten = TKind == TemplateName::Template ||
+                           TKind == TemplateName::UsingTemplate;
+      if (SimplyWritten && TemplateMatches)
         AcceptableReturnType = true;
       else {
         // This could still instantiate to the right type, unless we know it

diff  --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
index 33f70e5c019bb..cdc073066f3e3 100644
--- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
+++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
@@ -55,8 +55,6 @@ namespace WrongScope {
   }
   using N::NamedNS1;
   NamedNS1(int) -> NamedNS1<int>; // expected-error {{deduction guide must be declared in the same scope as template}}
-  // FIXME: remove the following bogus diagnostic
-  // expected-error at -2{{deduction guide is not written as a specialization of template 'NamedNS1'}}
 
   using namespace N;
   NamedNS2(int) -> NamedNS2<int>; // expected-error {{deduction guide must be declared in the same scope as template}}


        


More information about the cfe-commits mailing list