Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -421,8 +421,8 @@ if (CurrentToken->isOneOf(tok::r_square, tok::r_brace)) return false; - if (CurrentToken->is(tok::l_brace)) - OpeningParen.setType(TT_Unknown); // Not TT_ObjCBlockLParen + if (CurrentToken->is(tok::l_brace) && OpeningParen.is(TT_ObjCBlockLParen)) + OpeningParen.setType(TT_Unknown); if (CurrentToken->is(tok::comma) && CurrentToken->Next && !CurrentToken->Next->HasUnescapedNewline && !CurrentToken->Next->isTrailingComment()) Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23891,9 +23891,9 @@ verifyFormat( "template concept C = decltype([]() -> std::true_type {\n" " return {};\n" - " }())::value\n" - " && requires(T t) { t.bar(); } &&\n" - " sizeof(T) <= 8;", + " }())::value &&\n" + " requires(T t) { t.bar(); } && " + "sizeof(T) <= 8;", Style); verifyFormat("template concept Semiregular =\n" Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -331,6 +331,14 @@ EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_RequiresExpressionLBrace); EXPECT_TOKEN(Tokens[29], tok::kw_requires, TT_RequiresClauseInARequiresExpression); + + // Invalid Code, but we don't want to crash. See http://llvm.org/PR54350. + Tokens = annotate("bool r10 = requires (struct new_struct { int x; } s) { " + "requires true; };"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression); + EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen); + EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace); } TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {