diff options
-rw-r--r-- | clang/lib/AST/DeclPrinter.cpp | 15 | ||||
-rw-r--r-- | clang/test/Misc/ast-dump-templates.cpp | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 15b9a6de0bd..aedc35b0f84 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -481,6 +481,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D); CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D); + CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(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<CXXDestructorDecl>(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<CXXDeductionGuideDecl>(D->getTemplatedDecl())) { FunctionDecl *PrevDecl = D->getTemplatedDecl(); const FunctionDecl *Def; if (PrevDecl->isDefined(Def) && Def != PrevDecl) diff --git a/clang/test/Misc/ast-dump-templates.cpp b/clang/test/Misc/ast-dump-templates.cpp index eb493b42776..89feee75268 100644 --- a/clang/test/Misc/ast-dump-templates.cpp +++ b/clang/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 <int X, typename Y, int Z = 5> struct foo { @@ -61,3 +61,9 @@ void tmpl() { // DUMP: UnresolvedLookupExpr {{.*}} <col:3> '<overloaded function type>' lvalue (ADL) = 'func' } + +namespace test3 { + template<typename T> struct A {}; + template<typename T> A(T) -> A<int>; + // CHECK1: template <typename T> A(T) -> A<int>; +} |