This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGc9163901c8e1: [clang-format] Treat &/&& as reference when followed by requires clause (authored by rymiel).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D145656/new/ https://reviews.llvm.org/D145656 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -744,10 +744,15 @@ "void S::bar() const & requires Baz<T> { }"); 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) {}"); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24148,6 +24148,14 @@ "}", Style); + verifyFormat("template <typename T>\n" + "int S::bar(T t) &&\n" + " requires F<T>\n" + "{\n" + " return 5;\n" + "}", + Style); + verifyFormat("template <typename T>\n" "int bar(T t)\n" " requires F<T>;", @@ -24161,6 +24169,14 @@ "}", Style); + verifyFormat("template <typename T>\n" + "int S::bar(T t) &&\n" + "requires F<T>\n" + "{\n" + " return 5;\n" + "}", + Style); + verifyFormat("template <typename T>\n" "int bar(T t)\n" "requires F<T>\n" @@ -24174,6 +24190,7 @@ "template <typename T> requires Foo<T> void bar() {}\n" "template <typename T> void bar() requires Foo<T> {}\n" "template <typename T> void bar() requires Foo<T>;\n" + "template <typename T> void S::bar() && requires Foo<T> {}\n" "template <typename T> requires Foo<T> Bar(T) -> Bar<T>;", Style); @@ -24185,6 +24202,8 @@ "requires Foo<T> void bar() {}\n" "template <typename AAAAAAA>\n" "void bar() requires Foo<T> {}\n" + "template <typename T>\n" + "void S::bar() && requires Foo<T> {}\n" "template <typename AAAAAAA>\n" "requires Foo<T> Baz(T) -> Baz<T>;", ColumnStyle); @@ -24229,6 +24248,9 @@ "void bar()\n" "requires Foo<T>;\n" "template <typename T>\n" + "void S::bar() &&\n" + "requires Foo<T> {}\n" + "template <typename T>\n" "requires Foo<T> Bar(T) -> Bar<T>;", Style); @@ -24259,6 +24281,9 @@ "void bar()\n" " requires Foo<T> {}\n" "template <typename T>\n" + "void S::bar() &&\n" + " requires Foo<T> {}\n" + "template <typename T>\n" " requires Foo<T> Bar(T) -> Bar<T>;", Style); @@ -24289,6 +24314,9 @@ "void bar() requires Foo<T>\n" "{}\n" "template <typename T> void bar() requires Foo<T>;\n" + "template <typename T>\n" + "void S::bar() && requires Foo<T>\n" + "{}\n" "template <typename T> requires Foo<T>\n" "Bar(T) -> Bar<T>;", Style); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits