Skip to content

Commit 17ea830

Browse files
authored
[clang-format] Don't annotate enum colon as InheritanceColon (#138440)
Fix #61156
1 parent f69e267 commit 17ea830

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,8 +1422,9 @@ class AnnotatingParser {
14221422
} else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
14231423
Tok->setType(TT_BitFieldColon);
14241424
} else if (Contexts.size() == 1 &&
1425-
!Line.First->isOneOf(tok::kw_enum, tok::kw_case,
1426-
tok::kw_default)) {
1425+
!Line.getFirstNonComment()->isOneOf(tok::kw_enum, tok::kw_case,
1426+
tok::kw_default) &&
1427+
!Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
14271428
FormatToken *Prev = Tok->getPreviousNonComment();
14281429
if (!Prev)
14291430
break;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,12 @@ TEST_F(TokenAnnotatorTest, UserDefinedLiteral) {
40334033
EXPECT_EQ(Tokens[3]->TokenText, "2_$");
40344034
}
40354035

4036+
TEST_F(TokenAnnotatorTest, EnumColonInTypedef) {
4037+
auto Tokens = annotate("typedef enum : int {} foo;");
4038+
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
4039+
EXPECT_TOKEN(Tokens[2], tok::colon, TT_Unknown); // Not TT_InheritanceColon.
4040+
}
4041+
40364042
} // namespace
40374043
} // namespace format
40384044
} // namespace clang

0 commit comments

Comments
 (0)