From 7186ccc86ee5802c33886d6dd4c5386c7e9fd1aa Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 28 Aug 2013 08:04:23 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189453 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 8 +++++++- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 168b59e8ee..9e4600b430 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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()); } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 274d6e0064..24ba93f1b9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0