Skip to content

Commit

Permalink
Merge pull request #642 from andreasfertig/p0960
Browse files Browse the repository at this point in the history
Added support for P0960: Allow initializing aggregates from a parenthesized list of values
  • Loading branch information
andreasfertig authored Jun 11, 2024
2 parents 8e4c57b + 260d310 commit ceb8b6c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,9 @@ void CodeGenerator::InsertArg(const VarDecl* stmt)
if(not(ctorExpr and ctorExpr->getConstructor()->isDefaultConstructor() and
ctorExpr->getConstructor()->getParent()->hasTrivialDefaultConstructor())) {

mOutputFormatHelper.Append(hlpAssing);
if(not isa<CXXParenListInitExpr>(init)) {
mOutputFormatHelper.Append(hlpAssing);
}

if(GetInsightsOptions().ShowLifetime and init->isXValue() and
stmt->getType()->isRValueReferenceType()) {
Expand Down Expand Up @@ -2005,6 +2007,12 @@ void CodeGenerator::InsertArg(const ParenExpr* stmt)
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const CXXParenListInitExpr* stmt)
{
WrapInParens([&]() { ForEachArg(stmt->getInitExprs(), [&](const auto& init) { InsertArg(init); }); });
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const UnaryOperator* stmt)
{
StringRef opCodeName = UnaryOperator::getOpcodeStr(stmt->getOpcode());
Expand Down
1 change: 1 addition & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ SUPPORTED_STMT(ConceptSpecializationExpr)
SUPPORTED_STMT(RequiresExpr)
SUPPORTED_STMT(StmtExpr)
SUPPORTED_STMT(SourceLocExpr)
SUPPORTED_STMT(CXXParenListInitExpr)
SUPPORTED_STMT(CppInsightsCommentStmt)

#undef IGNORED_DECL
Expand Down
13 changes: 13 additions & 0 deletions tests/p0960Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// cmdline:-std=c++20

struct Point {
int y;
int x = 2;
int z;
};

int main()
{
Point p (2, 3, 4);
}

13 changes: 13 additions & 0 deletions tests/p0960Test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct Point
{
int y;
int x = 2;
int z;
};


int main()
{
Point p(2, 3, 4);
return 0;
}

0 comments on commit ceb8b6c

Please sign in to comment.