-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Fix the printout of CXXParenListInitExpr involving default arguments #130731
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
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesThe parantheses are unnecessary IMO because they should have been handled in the parents of such expressions, e.g. in CXXFunctionalCastExpr. Moreover, we shouldn't join CXXDefaultInitExpr either because they are not printed at all. Full diff: https://github.com/llvm/llvm-project/pull/130731.diff 3 Files Affected:
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index facdc4104c374..e0063ec5f25eb 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2659,10 +2659,8 @@ void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
}
void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
- OS << "(";
- llvm::interleaveComma(Node->getInitExprs(), OS,
+ llvm::interleaveComma(Node->getUserSpecifiedInitExprs(), OS,
[&](Expr *E) { PrintExpr(E); });
- OS << ")";
}
void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
diff --git a/clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp b/clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
index ce5eefc6bfdb4..09c6cb4a25421 100644
--- a/clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.decomp/p3.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
using size_t = decltype(sizeof(0));
@@ -301,3 +302,42 @@ template <> struct std::tuple_size<UsingGet> {
template <> struct std::tuple_element<0, UsingGet> { typedef int type; };
auto [y] = UsingGet();
+
+#if __cplusplus >= 202002L
+
+namespace DefaultArguments {
+
+struct S {
+ int a, b;
+ bool flag = false;
+
+ constexpr explicit operator bool() {
+ return a != b;
+ }
+
+ constexpr bool operator==(S rhs) {
+ return a == rhs.a && b == rhs.b;
+ }
+
+ template <int I>
+ constexpr int& get() {
+ return I == 0 ? a : b;
+ }
+};
+
+}
+
+template <> struct std::tuple_size<DefaultArguments::S> {
+ static const int value = 2;
+};
+
+template <int I> struct std::tuple_element<I, DefaultArguments::S> {
+ using type = int;
+};
+
+static_assert(DefaultArguments::S(1, 2) == DefaultArguments::S(1, 2));
+
+static_assert(DefaultArguments::S(1, 2) == DefaultArguments::S(3, 4));
+// expected-error@-1 {{failed due to requirement 'DefaultArguments::S(1, 2) == DefaultArguments::S(3, 4)'}}
+
+#endif
diff --git a/clang/test/CodeGen/p0963r3.cpp b/clang/test/CodeGen/p0963r3.cpp
index b48b5294e093e..4a5e6c3f5d751 100644
--- a/clang/test/CodeGen/p0963r3.cpp
+++ b/clang/test/CodeGen/p0963r3.cpp
@@ -139,9 +139,6 @@ constexpr int bar(auto) {
}();
static_assert(value == S(1, 2));
- // FIXME: The diagnostic message adds a trailing comma "static assertion failed due to requirement 'value == Case1::S((0, 1, ))'"
- // static_assert(value == S(0, 1));
-
constexpr auto value2 = [] {
if (auto [a, b] = S(1, 2))
return S(a, b);
|
…guments The parantheses are unnecessary IMO because they should have been handled in the parents of such expressions, e.g. in CXXFunctionalCastExpr. Moreover, we shouldn't join CXXDefaultInitExpr either because they are not printed at all.
dafb057
to
c643ba2
Compare
The CI failure seems relevant here |
Not a big deal. |
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.
LGTM, I am a bit discouraged that this did not alter an tests.
The parantheses are unnecessary IMO because they should have been handled in the parents of such expressions, e.g. in CXXFunctionalCastExpr.
Moreover, we shouldn't join CXXDefaultInitExpr either because they are not printed at all.