Skip to content

Commit 51ff7f3

Browse files
owencallvmbot
authored andcommitted
[clang-format] Fix a regression in annotating TrailingReturnArrow (llvm#86624)
Fixes llvm#86559. (cherry picked from commit a7f4576)
1 parent b544217 commit 51ff7f3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
35323532
}
35333533
} else if (ClosingParen) {
35343534
for (auto *Tok = ClosingParen->Next; Tok; Tok = Tok->Next) {
3535+
if (Tok->is(TT_CtorInitializerColon))
3536+
break;
35353537
if (Tok->is(tok::arrow)) {
35363538
Tok->setType(TT_TrailingReturnArrow);
35373539
break;

clang/unittests/Format/TokenAnnotatorTest.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) {
18721872
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
18731873
EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown);
18741874

1875+
Tokens = annotate("__attribute__((cold)) C() : Base(obj->func()) {}");
1876+
ASSERT_EQ(Tokens.size(), 21u) << Tokens;
1877+
EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
1878+
18751879
// Mixed
18761880
Tokens = annotate("auto f() -> int { auto a = b()->c; }");
18771881
ASSERT_EQ(Tokens.size(), 18u) << Tokens;

0 commit comments

Comments
 (0)