r189453 - clang-format: Fix corner case in ObjC interface definitions.

Daniel Jasper djasper at google.com
Wed Aug 28 01:04:23 PDT 2013


Author: djasper
Date: Wed Aug 28 03:04:23 2013
New Revision: 189453

URL: http://llvm.org/viewvc/llvm-project?rev=189453&view=rev
Log:
clang-format: Fix corner case in ObjC interface definitions.

In
  @implementation ObjcClass
  - (void)method;
  {
  }
  @end
the ObjC compiler seems to accept the superfluous comma after "method",
but clang-format used to assert on the subsequent "{".

This fixes llvm.org/PR16604.

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=189453&r1=189452&r2=189453&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Aug 28 03:04:23 2013
@@ -1030,7 +1030,13 @@ void UnwrappedLineParser::parseObjCUntil
       addUnwrappedLine();
       break;
     }
-    parseStructuralElement();
+    if (FormatTok->is(tok::l_brace)) {
+      parseBlock(/*MustBeDeclaration=*/false);
+      // In ObjC interfaces, nothing should be following the "}".
+      addUnwrappedLine();
+    } else {
+      parseStructuralElement();
+    }
   } while (!eof());
 }
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=189453&r1=189452&r2=189453&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 28 03:04:23 2013
@@ -4791,6 +4791,10 @@ TEST_F(FormatTest, FormatObjCImplementat
   verifyFormat("@implementation Foo (HackStuff)\n"
                "+ (id)init {\n}\n"
                "@end");
+  verifyFormat("@implementation ObjcClass\n"
+               "- (void)method;\n"
+               "{}\n"
+               "@end");
 }
 
 TEST_F(FormatTest, FormatObjCProtocol) {





More information about the cfe-commits mailing list