Skip to content

Commit 7e7f118

Browse files
authored
[clang-format] Handles Elaborated type specifier for enum in trailing return (#80085)
Fixes #80062
1 parent 7b9bf80 commit 7e7f118

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,8 @@ void UnwrappedLineParser::parseStructuralElement(
17601760
break;
17611761
}
17621762
case tok::kw_enum:
1763-
// Ignore if this is part of "template <enum ...".
1764-
if (Previous && Previous->is(tok::less)) {
1763+
// Ignore if this is part of "template <enum ..." or "... -> enum".
1764+
if (Previous && Previous->isOneOf(tok::less, tok::arrow)) {
17651765
nextToken();
17661766
break;
17671767
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,12 @@ TEST_F(TokenAnnotatorTest, StreamOperator) {
26442644
EXPECT_TRUE(Tokens[5]->MustBreakBefore);
26452645
}
26462646

2647+
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
2648+
auto Tokens = annotate("auto foo() -> enum En {}");
2649+
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
2650+
EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace);
2651+
}
2652+
26472653
} // namespace
26482654
} // namespace format
26492655
} // namespace clang

0 commit comments

Comments
 (0)