Skip to content

Commit c127618

Browse files
authored
[Clang] Fix the printout of CXXParenListInitExpr involving default arguments (#130731)
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.
1 parent 30fdeec commit c127618

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Bug Fixes to AST Handling
313313
^^^^^^^^^^^^^^^^^^^^^^^^^
314314
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)
315315
- Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. (#GH129198)
316+
- Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
316317

317318
Miscellaneous Bug Fixes
318319
^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/StmtPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,10 +2659,8 @@ void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
26592659
}
26602660

26612661
void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
2662-
OS << "(";
2663-
llvm::interleaveComma(Node->getInitExprs(), OS,
2662+
llvm::interleaveComma(Node->getUserSpecifiedInitExprs(), OS,
26642663
[&](Expr *E) { PrintExpr(E); });
2665-
OS << ")";
26662664
}
26672665

26682666
void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {

clang/test/CodeGen/p0963r3.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ constexpr int bar(auto) {
139139
}();
140140
static_assert(value == S(1, 2));
141141

142-
// FIXME: The diagnostic message adds a trailing comma "static assertion failed due to requirement 'value == Case1::S((0, 1, ))'"
143-
// static_assert(value == S(0, 1));
144-
145142
constexpr auto value2 = [] {
146143
if (auto [a, b] = S(1, 2))
147144
return S(a, b);

clang/test/SemaCXX/paren-list-agg-init.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,22 @@ ThroughAlias<int, 1> e(42);
357357
// beforecxx20-warning@-1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
358358

359359
}
360+
361+
namespace CXXParenListInitExpr {
362+
363+
struct S {
364+
int a, b;
365+
bool flag = false;
366+
367+
constexpr bool operator==(S rhs) {
368+
return a == rhs.a && b == rhs.b;
369+
}
370+
};
371+
372+
static_assert(S(1, 2) == S(1, 2)); // beforecxx20-warning 2{{C++20 extension}}
373+
374+
static_assert(S(1, 2) == S(3, 4));
375+
// expected-error@-1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 2) == CXXParenListInitExpr::S(3, 4)'}} \
376+
// beforecxx20-warning@-1 2{{C++20 extension}}
377+
378+
}

0 commit comments

Comments
 (0)