diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestObjC.cpp | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 7cde7ca88e7..8ab61f900c9 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1135,6 +1135,18 @@ void UnwrappedLineParser::parseStructuralElement() { } addUnwrappedLine(); return; + case tok::objc_synchronized: + nextToken(); + if (FormatTok->Tok.is(tok::l_paren)) + // Skip synchronization object + parseParens(); + if (FormatTok->Tok.is(tok::l_brace)) { + if (Style.BraceWrapping.AfterObjCDeclaration) + addUnwrappedLine(); + parseBlock(/*MustBeDeclaration=*/false); + } + addUnwrappedLine(); + return; case tok::objc_try: // This branch isn't strictly necessary (the kw_try case below would // do this too after the tok::at is parsed above). But be explicit. diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 40dc375d576..d592b39a482 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -209,6 +209,24 @@ TEST_F(FormatTestObjC, FormatObjCGenerics) { " aaaaaaaaaaaaaaaaa);\n"); } +TEST_F(FormatTestObjC, FormatObjCSynchronized) { + verifyFormat("@synchronized(self) {\n" + " f();\n" + "}\n" + "@synchronized(self) {\n" + " f();\n" + "}\n"); + Style.BreakBeforeBraces = FormatStyle::BS_Allman; + verifyFormat("@synchronized(self)\n" + "{\n" + " f();\n" + "}\n" + "@synchronized(self)\n" + "{\n" + " f();\n" + "}\n"); +} + TEST_F(FormatTestObjC, FormatObjCInterface) { verifyFormat("@interface Foo : NSObject <NSSomeDelegate> {\n" "@public\n" |