Skip to content

Commit

Permalink
[clang-format] Handles Elaborated type specifier for enum in trailing…
Browse files Browse the repository at this point in the history
… return (#80085)

Fixes #80062
  • Loading branch information
XDeme1 committed Feb 1, 2024
1 parent 7b9bf80 commit 7e7f118
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,8 @@ void UnwrappedLineParser::parseStructuralElement(
break;
}
case tok::kw_enum:
// Ignore if this is part of "template <enum ...".
if (Previous && Previous->is(tok::less)) {
// Ignore if this is part of "template <enum ..." or "... -> enum".
if (Previous && Previous->isOneOf(tok::less, tok::arrow)) {
nextToken();
break;
}
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,12 @@ TEST_F(TokenAnnotatorTest, StreamOperator) {
EXPECT_TRUE(Tokens[5]->MustBreakBefore);
}

TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
auto Tokens = annotate("auto foo() -> enum En {}");
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace);
}

} // namespace
} // namespace format
} // namespace clang

0 comments on commit 7e7f118

Please sign in to comment.