From a15da3068d6e0310ece35618a94e151681b5aa67 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 28 Aug 2013 08:04:23 +0000 Subject: 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. llvm-svn: 189453 --- clang/lib/Format/UnwrappedLineParser.cpp | 8 +++++++- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 168b59e8ee4..9e4600b430d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 274d6e0064b..24ba93f1b98 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { -- cgit v1.2.3