[llvm-branch-commits] [clang] b54051a - [clang-format] Correctly annotate RequiresExpressionLBrace (#155773)
Cullen Rhodes via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 14 06:25:02 PDT 2025
Author: owenca
Date: 2025-10-14T13:24:54Z
New Revision: b54051ac74cb0b8a8bd9a39a80c9a004774587c9
URL: https://github.com/llvm/llvm-project/commit/b54051ac74cb0b8a8bd9a39a80c9a004774587c9
DIFF: https://github.com/llvm/llvm-project/commit/b54051ac74cb0b8a8bd9a39a80c9a004774587c9.diff
LOG: [clang-format] Correctly annotate RequiresExpressionLBrace (#155773)
Fixes #155746
(cherry picked from commit c62a5bf52de2953cbfb73e1df64092f37d3fc192)
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 580996e870f54..3ab3c45bbb052 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4007,7 +4007,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
auto *Tok = Line.Last->Previous;
while (Tok->isNot(tok::r_brace))
Tok = Tok->Previous;
- if (auto *LBrace = Tok->MatchingParen; LBrace) {
+ if (auto *LBrace = Tok->MatchingParen; LBrace && LBrace->is(TT_Unknown)) {
assert(LBrace->is(tok::l_brace));
Tok->setBlockKind(BK_Block);
LBrace->setBlockKind(BK_Block);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 259d7e54133a1..5ef7f5ba25a12 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1349,6 +1349,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
+ Tokens = annotate("template <typename Foo>\n"
+ "void Fun(const Foo &F)\n"
+ " requires requires(Foo F) {\n"
+ " { F.Bar() } -> std::same_as<int>;\n"
+ " };");
+ ASSERT_EQ(Tokens.size(), 38u) << Tokens;
+ EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_RequiresExpressionLBrace);
+
Tokens =
annotate("template <class A, class B> concept C ="
"std::same_as<std::iter_value_t<A>, std::iter_value_t<B>>;");
More information about the llvm-branch-commits
mailing list