[clang] [Clang] Fix the printout of CXXParenListInitExpr involving default arguments (PR #130731)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 04:53:43 PDT 2025
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/130731
>From c643ba2de0bb3e5fcb6514b70c86e594badc396b Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Tue, 11 Mar 2025 14:18:20 +0800
Subject: [PATCH 1/3] [Clang] Fix the printout of CXXParenListInitExpr
involving default arguments
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.
---
clang/lib/AST/StmtPrinter.cpp | 4 +---
clang/test/CodeGen/p0963r3.cpp | 3 ---
clang/test/SemaCXX/paren-list-agg-init.cpp | 18 ++++++++++++++++++
3 files changed, 19 insertions(+), 6 deletions(-)
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/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);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 61afba85e1dff..c55604003bc33 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -357,3 +357,21 @@ ThroughAlias<int, 1> e(42);
// beforecxx20-warning at -1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
}
+
+namespace CXXParenListInitExpr {
+
+struct S {
+ int a, b;
+ bool flag = false;
+
+ constexpr bool operator==(S rhs) {
+ return a == rhs.a && b == rhs.b;
+ }
+};
+
+static_assert(S(1, 2) == S(1, 2));
+
+static_assert(S(1, 2) == S(3, 4));
+// expected-error at -1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+
+}
>From 2c6f6a193e895129151fd627ca2b490f6643126f Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Tue, 11 Mar 2025 17:43:30 +0800
Subject: [PATCH 2/3] Fix CI
---
clang/test/SemaCXX/paren-list-agg-init.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c55604003bc33..e5c0757d0970c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -372,6 +372,6 @@ struct S {
static_assert(S(1, 2) == S(1, 2));
static_assert(S(1, 2) == S(3, 4));
-// expected-error at -1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+// expected-error at -1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 2) == CXXParenListInitExpr::S(3, 4)'}}
}
>From ca9c153de00eba8efb2805a5b7c7bce7c9ba5ee2 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Tue, 11 Mar 2025 19:53:20 +0800
Subject: [PATCH 3/3] Fix it again
---
clang/test/SemaCXX/paren-list-agg-init.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index e5c0757d0970c..b2d0f2564bb59 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -369,9 +369,10 @@ struct S {
}
};
-static_assert(S(1, 2) == S(1, 2));
+static_assert(S(1, 2) == S(1, 2)); // beforecxx20-warning 2{{C++20 extension}}
static_assert(S(1, 2) == S(3, 4));
-// expected-error at -1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 2) == CXXParenListInitExpr::S(3, 4)'}}
+// expected-error at -1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 2) == CXXParenListInitExpr::S(3, 4)'}} \
+// beforecxx20-warning at -1 2{{C++20 extension}}
}
More information about the cfe-commits
mailing list