[clang] 2a948d1 - [Clang][AST] Let DeclPrinter print trailing requires expressions for template parameters (#96864)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 27 03:50:01 PDT 2024
Author: Younan Zhang
Date: 2024-06-27T18:49:58+08:00
New Revision: 2a948d11c0540004dc906d948bac58398bafe928
URL: https://github.com/llvm/llvm-project/commit/2a948d11c0540004dc906d948bac58398bafe928
DIFF: https://github.com/llvm/llvm-project/commit/2a948d11c0540004dc906d948bac58398bafe928.diff
LOG: [Clang][AST] Let DeclPrinter print trailing requires expressions for template parameters (#96864)
As discussed in
https://github.com/llvm/llvm-project/pull/96084#discussion_r1654629993,
it would be nice to present these trailing constraints on template
parameters when printing CTAD decls through a DeclPrinter.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclPrinter.cpp
clang/test/PCH/cxx2a-requires-expr.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index df579ae398c5e..da967fcdda808 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -115,6 +115,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<typename T::val> || (C<typename T::val> || C<T>);
};
}
+
+namespace trailing_requires_expression {
+
+template <typename T> requires C<T> && C2<T, T>
+// CHECK: template <typename T> requires C<T> && C2<T, T> void g();
+void g();
+
+template <typename T> requires C<T> || C2<T, T>
+// CHECK: template <typename T> requires C<T> || C2<T, T> constexpr int h = sizeof(T);
+constexpr int h = sizeof(T);
+
+template <typename T> requires C<T>
+// CHECK: template <typename T> requires C<T> class i {
+// CHECK-NEXT: };
+class i {};
+
+}
More information about the cfe-commits
mailing list