diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 87a0e43f8730e..3919bc0ef0b35 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3530,9 +3530,9 @@ void UnwrappedLineParser::parseConstraintExpression() { // concept C = bool(...); // and bool is the only type, all other types as cast must be inside a // cast to bool an thus are handled by the other cases. - nextToken(); - if (FormatTok->isNot(tok::l_paren)) + if (Tokens->peekNextToken()->isNot(tok::l_paren)) return; + nextToken(); parseParens(); break; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 6bc295c41798c..c8de8a2a2abe4 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -449,6 +449,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) { EXPECT_TRUE(Tokens[14]->ClosesRequiresClause); EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow); + Tokens = annotate("template \n" + "requires Bar\n" + "bool foo(T) { return false; }"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause); + EXPECT_TRUE(Tokens[9]->ClosesRequiresClause); + EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName); + Tokens = annotate("template \n" "struct S {\n" " void foo() const requires Bar;\n"