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 <zyn7...@gmail.com> Date: Tue, 11 Mar 2025 14:18:20 +0800 Subject: [PATCH] [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@-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@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits