Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ AST Dumping Potentially Breaking Changes
- Pretty-printing of templates with inherited (i.e. specified in a previous
redeclaration) default arguments has been fixed.

- Default arguments of template template parameters are pretty-printed now.

Clang Frontend Potentially Breaking Changes
-------------------------------------------
- Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``
Expand Down
14 changes: 12 additions & 2 deletions clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace {
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *);
void VisitHLSLBufferDecl(HLSLBufferDecl *D);

void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D);
Expand Down Expand Up @@ -1189,8 +1190,7 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
} else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
VisitNonTypeTemplateParmDecl(NTTP);
} else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
VisitTemplateDecl(TTPD);
// FIXME: print the default argument, if present.
VisitTemplateTemplateParmDecl(TTPD);
}
}

Expand Down Expand Up @@ -1916,6 +1916,16 @@ void DeclPrinter::VisitNonTypeTemplateParmDecl(
}
}

void DeclPrinter::VisitTemplateTemplateParmDecl(
const TemplateTemplateParmDecl *TTPD) {
VisitTemplateDecl(TTPD);
if (TTPD->hasDefaultArgument() && !TTPD->defaultArgumentWasInherited()) {
Out << " = ";
TTPD->getDefaultArgument().getArgument().print(Policy, Out,
/*IncludeType=*/false);
}
}

void DeclPrinter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) {
if (!D->isInvalidDecl()) {
Out << "#pragma acc declare";
Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/ast-print-record-decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,11 @@ template <int, int = 0> KW SmearedNTTPDefArgs;
// PRINT-CXX-NEXT: template <int = 0, int> [[KW]] SmearedNTTPDefArgs;
template <int = 0, int> KW SmearedNTTPDefArgs;

// PRINT-CXX-LABEL: Tpl
template <int> KW Tpl;
// PRINT-CXX-NEXT: template <template <int> class, template <int> class = Tpl> [[KW]] SmearedTplDefArgs;
template <template <int> class, template <int> class = Tpl> KW SmearedTplDefArgs;
// PRINT-CXX-NEXT: template <template <int> class = Tpl, template <int> class> [[KW]] SmearedTplDefArgs;
template <template <int> class = Tpl, template <int> class> KW SmearedTplDefArgs;

#endif
2 changes: 1 addition & 1 deletion clang/unittests/AST/DeclPrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ TEST(DeclPrinter, TestClassTemplateDecl9) {
"template<typename T> struct Z { };"
"template<template<typename U> class T = Z> struct A { };",
classTemplateDecl(hasName("A")).bind("id"),
"template <template <typename U> class T> struct A {}"));
"template <template <typename U> class T = Z> struct A {}"));
}

TEST(DeclPrinter, TestClassTemplateDecl10) {
Expand Down