From: Daniel Jasper Date: Fri, 19 Jun 2015 08:17:32 +0000 (+0000) Subject: clang-format: Better fix to detect elaborated enum return types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f68ad12985dd957b0661f07a524b2645d33f41bc;p=clang 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 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 6846158fb3..ea1ca39870 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1488,17 +1488,22 @@ void UnwrappedLineParser::parseEnum() { // Eat up enum class ... if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct)) nextToken(); + while (FormatTok->Tok.getIdentifierInfo() || FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less, tok::greater, tok::comma, tok::question)) { - if (FormatTok->is(tok::coloncolon)) - nextToken(); nextToken(); // We can have macros or attributes in between 'enum' and the enum name. if (FormatTok->is(tok::l_paren)) parseParens(); - if (FormatTok->is(tok::identifier)) + if (FormatTok->is(tok::identifier)) { 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. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 418b7aceea..30bc5b2cd1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2029,6 +2029,10 @@ TEST_F(FormatTest, FormatsEnum) { " a();\n" " return 42;\n" "}"); + verifyFormat("enum X Type::f() {\n" + " a();\n" + " return 42;\n" + "}"); verifyFormat("enum ::X f() {\n" " a();\n" " return 42;\n"