Fixes https://github.com/llvm/llvm-project/issues/53293.
After commit 5c2e7c9, the code:
```
template <> struct S : Template<int (*)[]> {};
```
was misformatted as:
```
template <> struct S : Template<int (*)[]>{};
```
Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D118106
if (!tryToParseBracedList())
break;
}
- if (FormatTok->is(tok::l_square) && !tryToParseLambda())
- break;
+ if (FormatTok->is(tok::l_square)) {
+ FormatToken *Previous = FormatTok->Previous;
+ if (!Previous || Previous->isNot(tok::r_paren)) {
+ // Don't try parsing a lambda if we had a closing parenthesis before,
+ // it was probably a pointer to an array: int (*)[].
+ if (!tryToParseLambda())
+ break;
+ }
+ }
if (FormatTok->Tok.is(tok::semi))
return;
if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
TEST_F(FormatTest, ShortTemplatedArgumentLists) {
auto Style = getLLVMStyle();
+ verifyFormat("template <> struct S : Template<int (*)[]> {};\n", Style);
+ verifyFormat("template <> struct S : Template<int (*)[10]> {};\n", Style);
verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
verifyFormat("struct Y<[] { return 0; }> {};", Style);