From a0f32072cd808c09524e8d469d3f7d4f866329c4 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 18 Feb 2017 01:01:48 +0000 Subject: [PATCH] Handle deduction guides better in -ast-print. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295521 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclPrinter.cpp | 15 ++++++++++++--- test/Misc/ast-dump-templates.cpp | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 15b9a6de0b..aedc35b0f8 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -481,6 +481,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConstructorDecl *CDecl = dyn_cast(D); CXXConversionDecl *ConversionDecl = dyn_cast(D); + CXXDeductionGuideDecl *GuideDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { switch (D->getStorageClass()) { case SC_None: break; @@ -496,13 +497,16 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (D->isModulePrivate()) Out << "__module_private__ "; if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr "; if ((CDecl && CDecl->isExplicitSpecified()) || - (ConversionDecl && ConversionDecl->isExplicit())) + (ConversionDecl && ConversionDecl->isExplicitSpecified()) || + (GuideDecl && GuideDecl->isExplicitSpecified())) Out << "explicit "; } PrintingPolicy SubPolicy(Policy); SubPolicy.SuppressSpecifiers = false; std::string Proto = D->getNameInfo().getAsString(); + if (GuideDecl) + Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString(); if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) { llvm::raw_string_ostream POut(Proto); DeclPrinter TArgPrinter(POut, SubPolicy, Indentation); @@ -652,7 +656,9 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } } else if (!ConversionDecl && !isa(D)) { if (FT && FT->hasTrailingReturn()) { - Out << "auto " << Proto << " -> "; + if (!GuideDecl) + Out << "auto "; + Out << Proto << " -> "; Proto.clear(); } AFT->getReturnType().print(Out, Policy, Proto); @@ -1044,7 +1050,10 @@ void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { prettyPrintPragmas(D->getTemplatedDecl()); VisitRedeclarableTemplateDecl(D); - if (PrintInstantiation) { + // Never print "instantiations" for deduction guides (they don't really + // have them). + if (PrintInstantiation && + !isa(D->getTemplatedDecl())) { FunctionDecl *PrevDecl = D->getTemplatedDecl(); const FunctionDecl *Def; if (PrevDecl->isDefined(Def) && Def != PrevDecl) diff --git a/test/Misc/ast-dump-templates.cpp b/test/Misc/ast-dump-templates.cpp index eb493b4277..89feee7526 100644 --- a/test/Misc/ast-dump-templates.cpp +++ b/test/Misc/ast-dump-templates.cpp @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -ast-print %s > %t +// RUN: %clang_cc1 -std=c++1z -ast-print %s > %t // RUN: FileCheck < %t %s -check-prefix=CHECK1 // RUN: FileCheck < %t %s -check-prefix=CHECK2 -// RUN: %clang_cc1 -ast-dump %s | FileCheck --check-prefix=DUMP %s +// RUN: %clang_cc1 -std=c++1z -ast-dump %s | FileCheck --check-prefix=DUMP %s template struct foo { @@ -61,3 +61,9 @@ void tmpl() { // DUMP: UnresolvedLookupExpr {{.*}} '' lvalue (ADL) = 'func' } + +namespace test3 { + template struct A {}; + template A(T) -> A; + // CHECK1: template A(T) -> A; +} -- 2.40.0