Author: owenca Date: 2025-11-23T10:08:37Z New Revision: a83e09a788926eb70acdfeee851c6c2fcefd0515
URL: https://github.com/llvm/llvm-project/commit/a83e09a788926eb70acdfeee851c6c2fcefd0515 DIFF: https://github.com/llvm/llvm-project/commit/a83e09a788926eb70acdfeee851c6c2fcefd0515.diff LOG: [clang-format] Handle `&&` in requires clause in requires requires (#169207) Fixes #152266 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index cb41756c56bf7..19c42c88762fb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3129,8 +3129,11 @@ class AnnotatingParser { // It is very unlikely that we are going to find a pointer or reference type // definition on the RHS of an assignment. - if (IsExpression && !Contexts.back().CaretFound) + if (IsExpression && !Contexts.back().CaretFound && + Line.getFirstNonComment()->isNot( + TT_RequiresClauseInARequiresExpression)) { return TT_BinaryOperator; + } // Opeartors at class scope are likely pointer or reference members. if (!Scopes.empty() && Scopes.back() == ST_Class) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 815c79e68dac9..6d769396589ee 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1391,6 +1391,15 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) { ASSERT_EQ(Tokens.size(), 38u) << Tokens; EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_RequiresExpressionLBrace); + Tokens = + annotate("template <typename... Ts>\n" + " requires requires {\n" + " requires std::same_as<int, SomeTemplate<void(Ts &&...)>>;\n" + " }\n" + "void Foo();"); + ASSERT_EQ(Tokens.size(), 34u) << Tokens; + EXPECT_TOKEN(Tokens[21], tok::ampamp, TT_PointerOrReference); + Tokens = annotate("template <class A, class B> concept C =" "std::same_as<std::iter_value_t<A>, std::iter_value_t<B>>;"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
