https://github.com/owenca created https://github.com/llvm/llvm-project/pull/155773
Fixes #155746 >From b4aa8211c5b2f29e92ce7fe6a49c24c70ad29032 Mon Sep 17 00:00:00 2001 From: Owen Pan <[email protected]> Date: Thu, 28 Aug 2025 00:39:51 -0700 Subject: [PATCH] [clang-format] Correctly annotate RequiresExpressionLBrace Fixes #155746 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/TokenAnnotatorTest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a220de54f46bf..27a06695fc0d9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4012,7 +4012,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 85ccba38ac8ca..141b0001cb52d 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>>;"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
