Skip to content
Snippets Groups Projects
Commit f68ad129 authored by Daniel Jasper's avatar Daniel Jasper
Browse files

clang-format: Better fix to detect elaborated enum return types.

The previous one (r240021) regressed:
  enum E Type::f() { .. }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240127 91177308-0d34-0410-b5e6-96231b3b80d8
parent a07c2fc3
No related branches found
No related tags found
No related merge requests found
...@@ -1488,17 +1488,22 @@ void UnwrappedLineParser::parseEnum() { ...@@ -1488,17 +1488,22 @@ void UnwrappedLineParser::parseEnum() {
// Eat up enum class ... // Eat up enum class ...
if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct)) if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct))
nextToken(); nextToken();
while (FormatTok->Tok.getIdentifierInfo() || while (FormatTok->Tok.getIdentifierInfo() ||
FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less, FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
tok::greater, tok::comma, tok::question)) { tok::greater, tok::comma, tok::question)) {
if (FormatTok->is(tok::coloncolon))
nextToken();
nextToken(); nextToken();
// We can have macros or attributes in between 'enum' and the enum name. // We can have macros or attributes in between 'enum' and the enum name.
if (FormatTok->is(tok::l_paren)) if (FormatTok->is(tok::l_paren))
parseParens(); parseParens();
if (FormatTok->is(tok::identifier)) if (FormatTok->is(tok::identifier)) {
nextToken(); nextToken();
// If there are two identifiers in a row, this is likely an elaborate
// return type. In Java, this can be "implements", etc.
if (Style.Language == FormatStyle::LK_Cpp &&
FormatTok->is(tok::identifier))
return;
}
} }
// Just a declaration or something is wrong. // Just a declaration or something is wrong.
......
...@@ -2029,6 +2029,10 @@ TEST_F(FormatTest, FormatsEnum) { ...@@ -2029,6 +2029,10 @@ TEST_F(FormatTest, FormatsEnum) {
" a();\n" " a();\n"
" return 42;\n" " return 42;\n"
"}"); "}");
verifyFormat("enum X Type::f() {\n"
" a();\n"
" return 42;\n"
"}");
verifyFormat("enum ::X f() {\n" verifyFormat("enum ::X f() {\n"
" a();\n" " a();\n"
" return 42;\n" " return 42;\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment