]> granicus.if.org Git - clang/commitdiff
clang-format: Fix corner case in ObjC interface definitions.
authorDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 08:04:23 +0000 (08:04 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 08:04:23 +0000 (08:04 +0000)
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.

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

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

index 168b59e8ee49d73e457e8abee180591a6c319d4d..9e4600b430dbff8afab81569dfe89772f66a1463 100644 (file)
@@ -1030,7 +1030,13 @@ void UnwrappedLineParser::parseObjCUntilAtEnd() {
       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());
 }
 
index 274d6e0064bdf69a167ef826ebd9cad6854911ed..24ba93f1b984955f86f3a9193fa22e7f00e67801 100644 (file)
@@ -4791,6 +4791,10 @@ TEST_F(FormatTest, FormatObjCImplementation) {
   verifyFormat("@implementation Foo (HackStuff)\n"
                "+ (id)init {\n}\n"
                "@end");
+  verifyFormat("@implementation ObjcClass\n"
+               "- (void)method;\n"
+               "{}\n"
+               "@end");
 }
 
 TEST_F(FormatTest, FormatObjCProtocol) {