diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 37fad4d9f49de2..eb927b5c492174 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3057,7 +3057,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { } if (FormatTok->is(tok::l_square)) { FormatToken *Previous = FormatTok->Previous; - if (!Previous || Previous->isNot(tok::r_paren)) { + if (!Previous || + !(Previous->is(tok::r_paren) || Previous->isTypeOrIdentifier())) { // Don't try parsing a lambda if we had a closing parenthesis before, // it was probably a pointer to an array: int (*)[]. if (!tryToParseLambda()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 094b9142aa10fb..96efc0e029e0ca 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -23665,6 +23665,7 @@ TEST_F(FormatTest, ShortTemplatedArgumentLists) { verifyFormat("struct Y<[] { return 0; }> {};", Style); verifyFormat("struct Z : X {};", Style); + verifyFormat("template struct Foo {};", Style); } TEST_F(FormatTest, RemoveBraces) {