Skip to content

Commit b89f52d

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f43721a4185c' from llvm.org/main into next
2 parents a97ba07 + f43721a commit b89f52d

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ AST Dumping Potentially Breaking Changes
126126
- Pretty-printing of templates with inherited (i.e. specified in a previous
127127
redeclaration) default arguments has been fixed.
128128

129+
- Default arguments of template template parameters are pretty-printed now.
130+
129131
Clang Frontend Potentially Breaking Changes
130132
-------------------------------------------
131133
- Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``

clang/lib/AST/DeclPrinter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace {
111111
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
112112
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
113113
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
114+
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *);
114115
void VisitHLSLBufferDecl(HLSLBufferDecl *D);
115116

116117
void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D);
@@ -1191,8 +1192,7 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
11911192
} else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
11921193
VisitNonTypeTemplateParmDecl(NTTP);
11931194
} else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1194-
VisitTemplateDecl(TTPD);
1195-
// FIXME: print the default argument, if present.
1195+
VisitTemplateTemplateParmDecl(TTPD);
11961196
}
11971197
}
11981198

@@ -1918,6 +1918,16 @@ void DeclPrinter::VisitNonTypeTemplateParmDecl(
19181918
}
19191919
}
19201920

1921+
void DeclPrinter::VisitTemplateTemplateParmDecl(
1922+
const TemplateTemplateParmDecl *TTPD) {
1923+
VisitTemplateDecl(TTPD);
1924+
if (TTPD->hasDefaultArgument() && !TTPD->defaultArgumentWasInherited()) {
1925+
Out << " = ";
1926+
TTPD->getDefaultArgument().getArgument().print(Policy, Out,
1927+
/*IncludeType=*/false);
1928+
}
1929+
}
1930+
19211931
void DeclPrinter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) {
19221932
if (!D->isInvalidDecl()) {
19231933
Out << "#pragma acc declare";

clang/test/AST/ast-print-record-decl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,11 @@ template <int, int = 0> KW SmearedNTTPDefArgs;
315315
// PRINT-CXX-NEXT: template <int = 0, int> [[KW]] SmearedNTTPDefArgs;
316316
template <int = 0, int> KW SmearedNTTPDefArgs;
317317

318+
// PRINT-CXX-LABEL: Tpl
319+
template <int> KW Tpl;
320+
// PRINT-CXX-NEXT: template <template <int> class, template <int> class = Tpl> [[KW]] SmearedTplDefArgs;
321+
template <template <int> class, template <int> class = Tpl> KW SmearedTplDefArgs;
322+
// PRINT-CXX-NEXT: template <template <int> class = Tpl, template <int> class> [[KW]] SmearedTplDefArgs;
323+
template <template <int> class = Tpl, template <int> class> KW SmearedTplDefArgs;
324+
318325
#endif

clang/unittests/AST/DeclPrinterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ TEST(DeclPrinter, TestClassTemplateDecl9) {
10901090
"template<typename T> struct Z { };"
10911091
"template<template<typename U> class T = Z> struct A { };",
10921092
classTemplateDecl(hasName("A")).bind("id"),
1093-
"template <template <typename U> class T> struct A {}"));
1093+
"template <template <typename U> class T = Z> struct A {}"));
10941094
}
10951095

10961096
TEST(DeclPrinter, TestClassTemplateDecl10) {

0 commit comments

Comments
 (0)