Index: cfe/trunk/lib/AST/ASTDumper.cpp =================================================================== --- cfe/trunk/lib/AST/ASTDumper.cpp +++ cfe/trunk/lib/AST/ASTDumper.cpp @@ -98,10 +98,14 @@ void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); void dumpTemplateParameters(const TemplateParameterList *TPL); void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); - void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A); + void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, + const Decl *From = nullptr, + const char *label = nullptr); void dumpTemplateArgumentList(const TemplateArgumentList &TAL); void dumpTemplateArgument(const TemplateArgument &A, - SourceRange R = SourceRange()); + SourceRange R = SourceRange(), + const Decl *From = nullptr, + const char *label = nullptr); template void dumpTemplateDeclSpecialization(const SpecializationDecl *D, bool DumpExplicitInst, @@ -673,8 +677,9 @@ dumpTemplateArgumentLoc(TALI[i]); } -void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) { - dumpTemplateArgument(A.getArgument(), A.getSourceRange()); +void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, + const Decl *From, const char *label) { + dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, label); } void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { @@ -682,12 +687,17 @@ dumpTemplateArgument(TAL[i]); } -void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) { +void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R, + const Decl *From, const char *label) { dumpChild([=] { OS << "TemplateArgument"; if (R.isValid()) NodeDumper.dumpSourceRange(R); + if (From) { + dumpDeclRef(From, label); + } + switch (A.getKind()) { case TemplateArgument::Null: OS << " null"; @@ -1380,10 +1390,10 @@ OS << " ..."; NodeDumper.dumpName(D); if (D->hasDefaultArgument()) - dumpTemplateArgument(D->getDefaultArgument()); - if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpTemplateArgument(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" + : "previous"); } void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { @@ -1393,10 +1403,10 @@ OS << " ..."; NodeDumper.dumpName(D); if (D->hasDefaultArgument()) - dumpTemplateArgument(D->getDefaultArgument()); - if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpTemplateArgument(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" + : "previous"); } void ASTDumper::VisitTemplateTemplateParmDecl( @@ -1407,10 +1417,9 @@ NodeDumper.dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); if (D->hasDefaultArgument()) - dumpTemplateArgumentLoc(D->getDefaultArgument()); - if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpTemplateArgumentLoc( + D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitUsingDecl(const UsingDecl *D) { Index: cfe/trunk/test/AST/ast-dump-decl.cpp =================================================================== --- cfe/trunk/test/AST/ast-dump-decl.cpp +++ cfe/trunk/test/AST/ast-dump-decl.cpp @@ -328,20 +328,20 @@ // CHECK: ClassTemplateDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} TestTemplateDefaultType // CHECK-NEXT: TemplateTypeParmDecl // CHECK-NEXT: TemplateArgument type 'int' -// CHECK-NEXT: inherited from TemplateTypeParm 0x{{[^ ]*}} 'T' +// CHECK-NEXT: inherited from TemplateTypeParm 0x{{[^ ]*}} 'T' // CHECK: ClassTemplateDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} TestTemplateDefaultNonType // CHECK-NEXT: NonTypeTemplateParmDecl // CHECK-NEXT: TemplateArgument expr +// CHECK-NEXT: inherited from NonTypeTemplateParm 0x{{[^ ]*}} 'I' 'int' // CHECK-NEXT: ConstantExpr // CHECK-NEXT: IntegerLiteral -// CHECK-NEXT: inherited from NonTypeTemplateParm 0x{{[^ ]*}} 'I' 'int' // CHECK: ClassTemplateDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} TestTemplateTemplateDefaultType // CHECK-NEXT: TemplateTemplateParmDecl // CHECK-NEXT: TemplateTypeParmDecl // CHECK-NEXT: TemplateArgument -// CHECK-NEXT: inherited from TemplateTemplateParm 0x{{[^ ]*}} 'TT' +// CHECK-NEXT: inherited from TemplateTemplateParm 0x{{[^ ]*}} 'TT' // PR15220 dump instantiation only once namespace testCanonicalTemplate {