Skip to content

Commit 1e2b9f3

Browse files
owencatomtor
authored andcommitted
[clang-format] Fix a bug in annotating braces (llvm#144095)
Stop looking for function decls after hitting a BK_BracedInit brace. Fixes llvm#144057.
1 parent 11ce566 commit 1e2b9f3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3978,7 +3978,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39783978
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
39793979
? FirstNonComment->Next
39803980
: nullptr;
3981-
Tok; Tok = Tok->Next) {
3981+
Tok && Tok->isNot(BK_BracedInit); Tok = Tok->Next) {
39823982
if (Tok->is(TT_StartOfName))
39833983
SeenName = true;
39843984
if (Tok->Previous->EndsCppAttributeGroup)

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,6 +3754,13 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
37543754
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
37553755
EXPECT_BRACE_KIND(Tokens[4], BK_BracedInit);
37563756
EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
3757+
3758+
Tokens = annotate("auto f1{&T::operator()};");
3759+
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
3760+
EXPECT_BRACE_KIND(Tokens[2], BK_BracedInit);
3761+
// Not TT_FunctionDeclarationName.
3762+
EXPECT_TOKEN(Tokens[6], tok::kw_operator, TT_Unknown);
3763+
EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
37573764
}
37583765

37593766
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

0 commit comments

Comments
 (0)