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->is(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,13 @@ 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_EQ(Tokens[11]->FakeLParens.size(), 0u); + EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause); + Tokens = annotate("template \n" "struct S {\n" " void foo() const requires Bar;\n"