-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][AST] Let DeclPrinter print trailing requires expressions for template parameters #96864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…template parameters 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.
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesAs discussed in #96084 (comment), it would be nice to present these trailing constraints on template parameters when printing CTAD decls through a DeclPrinter. Full diff: https://github.com/llvm/llvm-project/pull/96864.diff 3 Files Affected:
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..0a081e7e07ca8 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1189,6 +1189,16 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
Out << '>';
if (!OmitTemplateKW)
Out << ' ';
+
+ if (const Expr *RequiresClause = Params->getRequiresClause()) {
+ if (OmitTemplateKW)
+ Out << ' ';
+ Out << "requires ";
+ RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n",
+ &Context);
+ if (!OmitTemplateKW)
+ Out << ' ';
+ }
}
void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args,
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 {};
+
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, looks good.
…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.
…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.
As discussed in #96084 (comment), it would be nice to present these trailing constraints on template parameters when printing CTAD decls through a DeclPrinter.