Skip to content

Commit 5c2e7c9

Browse files
[clang-format] Ensure we can correctly parse lambda in the template argument list
#46505 The presence of a lambda in an argument template list ignored the [] as a lambda at all, this caused the contents of the <> to be incorrectly analyzed. ``` struct Y : X < [] { return 0; } > {}; ``` Fixes: #46505 Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D116806
1 parent 5ff916a commit 5c2e7c9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
28742874
if (!tryToParseBracedList())
28752875
break;
28762876
}
2877+
if (FormatTok->is(tok::l_square) && !tryToParseLambda())
2878+
break;
28772879
if (FormatTok->Tok.is(tok::semi))
28782880
return;
28792881
if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23212,6 +23212,15 @@ TEST_F(FormatTest, EmptyShortBlock) {
2321223212
Style);
2321323213
}
2321423214

23215+
TEST_F(FormatTest, ShortTemplatedArgumentLists) {
23216+
auto Style = getLLVMStyle();
23217+
23218+
verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
23219+
verifyFormat("struct Y<[] { return 0; }> {};", Style);
23220+
23221+
verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
23222+
}
23223+
2321523224
} // namespace
2321623225
} // namespace format
2321723226
} // namespace clang

0 commit comments

Comments
 (0)