https://github.com/owenca created https://github.com/llvm/llvm-project/pull/169207
Fixes #152266 >From 7a623cd42ce3426b6d1532d40a8069d5f70592d8 Mon Sep 17 00:00:00 2001 From: Owen Pan <[email protected]> Date: Thu, 7 Aug 2025 00:59:16 -0700 Subject: [PATCH] [clang-format] Handle `&&` in requires clause in requires requires Fixes #152266 --- clang/lib/Format/TokenAnnotator.cpp | 5 ++++- clang/unittests/Format/TokenAnnotatorTest.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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
