diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 69aea6c21ad39..03b1daa6597cd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -99,6 +99,7 @@ AST Dumping Potentially Breaking Changes ---------------------------------------- - The text ast-dumper has improved printing of TemplateArguments. +- The text decl-dumper prints template parameters' trailing requires expressions now. Clang Frontend Potentially Breaking Changes ------------------------------------------- diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..26773a69ab9ac 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1187,6 +1187,13 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params, } Out << '>'; + + if (const Expr *RequiresClause = Params->getRequiresClause()) { + Out << " requires "; + RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); + } + if (!OmitTemplateKW) Out << ' '; } diff --git a/clang/test/PCH/cxx2a-requires-expr.cpp b/clang/test/PCH/cxx2a-requires-expr.cpp index 7f8f258a0f8f3..936f601685463 100644 --- a/clang/test/PCH/cxx2a-requires-expr.cpp +++ b/clang/test/PCH/cxx2a-requires-expr.cpp @@ -22,3 +22,20 @@ bool f() { requires C || (C || C); }; } + +namespace trailing_requires_expression { + +template requires C && C2 +// CHECK: template requires C && C2 void g(); +void g(); + +template requires C || C2 +// CHECK: template requires C || C2 constexpr int h = sizeof(T); +constexpr int h = sizeof(T); + +template requires C +// CHECK: template requires C class i { +// CHECK-NEXT: }; +class i {}; + +}