[clang-format] Ensure we can correctly parse lambda in the template argument list

https://github.com/llvm/llvm-project/issues/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
This commit is contained in:
mydeveloperday 2022-01-10 08:28:42 +00:00
parent 5ff916ab72
commit 5c2e7c9ca0
2 changed files with 11 additions and 0 deletions

View File

@ -2874,6 +2874,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
if (!tryToParseBracedList())
break;
}
if (FormatTok->is(tok::l_square) && !tryToParseLambda())
break;
if (FormatTok->Tok.is(tok::semi))
return;
if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {

View File

@ -23212,6 +23212,15 @@ TEST_F(FormatTest, EmptyShortBlock) {
Style);
}
TEST_F(FormatTest, ShortTemplatedArgumentLists) {
auto Style = getLLVMStyle();
verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
verifyFormat("struct Y<[] { return 0; }> {};", Style);
verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
}
} // namespace
} // namespace format
} // namespace clang