diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2611,8 +2611,10 @@ } if (Current->is(TT_BinaryOperator) || Current->is(tok::comma)) return Current->getPrecedence(); - if (Current->isOneOf(tok::period, tok::arrow)) + if (Current->isOneOf(tok::period, tok::arrow) && + Current->isNot(TT_TrailingReturnArrow)) { return PrecedenceArrowAndPeriod; + } if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) && Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements, Keywords.kw_throws)) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -440,6 +440,15 @@ ASSERT_EQ(Tokens.size(), 18u) << Tokens; EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause); + Tokens = annotate("template \n" + "requires Bar || Baz\n" + "auto foo(T) -> int;"); + ASSERT_EQ(Tokens.size(), 24u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause); + EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u); + EXPECT_TRUE(Tokens[14]->ClosesRequiresClause); + EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow); + Tokens = annotate("template \n" "struct S {\n" " void foo() const requires Bar;\n"