clang-format: Better fix to detect elaborated enum return types.
authorDaniel Jasper <djasper@google.com>
Fri, 19 Jun 2015 08:17:32 +0000 (08:17 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 19 Jun 2015 08:17:32 +0000 (08:17 +0000)
The previous one (r240021) regressed:
  enum E Type::f() { .. }

llvm-svn: 240127

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index 6846158..ea1ca39 100644 (file)
@@ -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.
index 418b7ac..30bc5b2 100644 (file)
@@ -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"