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

Daniel Jasper djasper at google.com
Fri Jun 19 01:17:32 PDT 2015


Author: djasper
Date: Fri Jun 19 03:17:32 2015
New Revision: 240127

URL: http://llvm.org/viewvc/llvm-project?rev=240127&view=rev
Log:
clang-format: Better fix to detect elaborated enum return types.

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

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=240127&r1=240126&r2=240127&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jun 19 03:17:32 2015
@@ -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.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=240127&r1=240126&r2=240127&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jun 19 03:17:32 2015
@@ -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"





More information about the cfe-commits mailing list