Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -3183,6 +3183,11 @@ break; } default: + if (PreviousNonComment->isTypeOrIdentifier()) { + // This is a requires clause. + parseRequiresClause(RequiresToken); + return true; + } // It's an expression. parseRequiresExpression(RequiresToken); return false; Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -402,6 +402,33 @@ EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener); EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser); EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser); + + Tokens = annotate("auto bar() -> int requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause); + + Tokens = annotate("auto bar() -> void requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause); + + Tokens = annotate("auto bar() -> MyType requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause); + + Tokens = + annotate("auto bar() -> SOME_MACRO_TYPE requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause); + + Tokens = + annotate("auto bar() -> qualified::type requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 18u) << Tokens; + EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause); + + Tokens = + annotate("auto bar() -> Template requires(is_integral_v) {}"); + ASSERT_EQ(Tokens.size(), 19u) << Tokens; + EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {