Skip to content

Commit 255582c

Browse files
zyn0217AlexisPerry
authored andcommitted
[Clang][AST] Let DeclPrinter print trailing requires expressions for template parameters (llvm#96864)
As discussed in llvm#96084 (comment), it would be nice to present these trailing constraints on template parameters when printing CTAD decls through a DeclPrinter.
1 parent 344fd9c commit 255582c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ AST Dumping Potentially Breaking Changes
115115
----------------------------------------
116116

117117
- The text ast-dumper has improved printing of TemplateArguments.
118+
- The text decl-dumper prints template parameters' trailing requires expressions now.
118119

119120
Clang Frontend Potentially Breaking Changes
120121
-------------------------------------------

clang/lib/AST/DeclPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,13 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
11871187
}
11881188

11891189
Out << '>';
1190+
1191+
if (const Expr *RequiresClause = Params->getRequiresClause()) {
1192+
Out << " requires ";
1193+
RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n",
1194+
&Context);
1195+
}
1196+
11901197
if (!OmitTemplateKW)
11911198
Out << ' ';
11921199
}

clang/test/PCH/cxx2a-requires-expr.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ bool f() {
2222
requires C<typename T::val> || (C<typename T::val> || C<T>);
2323
};
2424
}
25+
26+
namespace trailing_requires_expression {
27+
28+
template <typename T> requires C<T> && C2<T, T>
29+
// CHECK: template <typename T> requires C<T> && C2<T, T> void g();
30+
void g();
31+
32+
template <typename T> requires C<T> || C2<T, T>
33+
// CHECK: template <typename T> requires C<T> || C2<T, T> constexpr int h = sizeof(T);
34+
constexpr int h = sizeof(T);
35+
36+
template <typename T> requires C<T>
37+
// CHECK: template <typename T> requires C<T> class i {
38+
// CHECK-NEXT: };
39+
class i {};
40+
41+
}

0 commit comments

Comments
 (0)