]> granicus.if.org Git - clang/commitdiff
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() { .. }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240127 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6846158fb3a554e60fb8934e0c184242b4f8cb9d..ea1ca39870e05a43f2eca8073be4175afdc15e49 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 418b7aceea67232da0a984c15c94b6ba4c3d8574..30bc5b2cd1d6f0c202fe6598ff38a155897fcfd9 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"