diff options
author | Daniel Jasper <djasper@google.com> | 2013-08-28 08:04:23 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-08-28 08:04:23 +0000 |
commit | a15da3068d6e0310ece35618a94e151681b5aa67 (patch) | |
tree | 4f7b416df020821cfaca0cb86fcd81e4d6cc51e7 | |
parent | fce1b03ee7e64214389ab5e17394cb75d99f77aa (diff) | |
download | bcm5719-llvm-a15da3068d6e0310ece35618a94e151681b5aa67.tar.gz bcm5719-llvm-a15da3068d6e0310ece35618a94e151681b5aa67.zip |
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
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 11 insertions, 1 deletions
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) { |