Skip to content

Commit b54051a

Browse files
owencac-rhodes
authored andcommitted
[clang-format] Correctly annotate RequiresExpressionLBrace (llvm#155773)
Fixes llvm#155746 (cherry picked from commit c62a5bf)
1 parent c9fbd57 commit b54051a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4007,7 +4007,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
40074007
auto *Tok = Line.Last->Previous;
40084008
while (Tok->isNot(tok::r_brace))
40094009
Tok = Tok->Previous;
4010-
if (auto *LBrace = Tok->MatchingParen; LBrace) {
4010+
if (auto *LBrace = Tok->MatchingParen; LBrace && LBrace->is(TT_Unknown)) {
40114011
assert(LBrace->is(tok::l_brace));
40124012
Tok->setBlockKind(BK_Block);
40134013
LBrace->setBlockKind(BK_Block);

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
13491349
EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
13501350
EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
13511351

1352+
Tokens = annotate("template <typename Foo>\n"
1353+
"void Fun(const Foo &F)\n"
1354+
" requires requires(Foo F) {\n"
1355+
" { F.Bar() } -> std::same_as<int>;\n"
1356+
" };");
1357+
ASSERT_EQ(Tokens.size(), 38u) << Tokens;
1358+
EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_RequiresExpressionLBrace);
1359+
13521360
Tokens =
13531361
annotate("template <class A, class B> concept C ="
13541362
"std::same_as<std::iter_value_t<A>, std::iter_value_t<B>>;");

0 commit comments

Comments
 (0)