[clang] [clang-format] Handle `&&` in requires clause in requires requires (PR #169207)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 23 01:42:26 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: owenca (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->152266
---
Full diff: https://github.com/llvm/llvm-project/pull/169207.diff
2 Files Affected:
- (modified) clang/lib/Format/TokenAnnotator.cpp (+4-1)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+9)
``````````diff
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>>;");
``````````
</details>
https://github.com/llvm/llvm-project/pull/169207
More information about the cfe-commits
mailing list