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 @@ -2400,7 +2400,7 @@ if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept, tok::comma, - tok::r_paren) || + tok::r_paren, TT_RequiresClause) || NextToken->canBePointerOrReferenceQualifier() || (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) { return TT_PointerOrReference; @@ -3758,8 +3758,9 @@ if (Right.is(TT_BlockComment)) return true; // foo() -> const Bar * override/final - if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final, - tok::kw_noexcept) && + // S::foo() & noexcept/requires + if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final, tok::kw_noexcept, + TT_RequiresClause) && !Right.is(TT_StartOfName)) { return true; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24148,6 +24148,14 @@ "}", Style); + verifyFormat("template \n" + "int S::bar(T t) &&\n" + " requires F\n" + "{\n" + " return 5;\n" + "}", + Style); + verifyFormat("template \n" "int bar(T t)\n" " requires F;", @@ -24161,6 +24169,14 @@ "}", Style); + verifyFormat("template \n" + "int S::bar(T t) &&\n" + "requires F\n" + "{\n" + " return 5;\n" + "}", + Style); + verifyFormat("template \n" "int bar(T t)\n" "requires F\n" @@ -24174,6 +24190,7 @@ "template requires Foo void bar() {}\n" "template void bar() requires Foo {}\n" "template void bar() requires Foo;\n" + "template void S::bar() && requires Foo {}\n" "template requires Foo Bar(T) -> Bar;", Style); @@ -24185,6 +24202,8 @@ "requires Foo void bar() {}\n" "template \n" "void bar() requires Foo {}\n" + "template \n" + "void S::bar() && requires Foo {}\n" "template \n" "requires Foo Baz(T) -> Baz;", ColumnStyle); @@ -24229,6 +24248,9 @@ "void bar()\n" "requires Foo;\n" "template \n" + "void S::bar() &&\n" + "requires Foo {}\n" + "template \n" "requires Foo Bar(T) -> Bar;", Style); @@ -24259,6 +24281,9 @@ "void bar()\n" " requires Foo {}\n" "template \n" + "void S::bar() &&\n" + " requires Foo {}\n" + "template \n" " requires Foo Bar(T) -> Bar;", Style); @@ -24289,6 +24314,9 @@ "void bar() requires Foo\n" "{}\n" "template void bar() requires Foo;\n" + "template \n" + "void S::bar() && requires Foo\n" + "{}\n" "template requires Foo\n" "Bar(T) -> Bar;", Style); 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 @@ -744,10 +744,15 @@ "void S::bar() const & requires Baz { }"); ASSERT_EQ(Tokens.size(), 85u) << Tokens; EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[24], tok::amp, TT_PointerOrReference); EXPECT_TOKEN(Tokens[25], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[35], tok::ampamp, TT_PointerOrReference); EXPECT_TOKEN(Tokens[36], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[47], tok::amp, TT_PointerOrReference); EXPECT_TOKEN(Tokens[49], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[59], tok::ampamp, TT_PointerOrReference); EXPECT_TOKEN(Tokens[61], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[76], tok::amp, TT_PointerOrReference); EXPECT_TOKEN(Tokens[77], tok::kw_requires, TT_RequiresClause); Tokens = annotate("void Class::member() && requires(Constant) {}");