diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f22c0ab581a5..d721536c76ba 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -104,6 +104,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.SplitTemplateClosingGreater = true; LLVMStyle.IndentCaseLabels = false; LLVMStyle.SpacesBeforeTrailingComments = 1; + LLVMStyle.ObjCSpaceBeforeProtocolList = true; return LLVMStyle; } @@ -116,6 +117,7 @@ FormatStyle getGoogleStyle() { GoogleStyle.SplitTemplateClosingGreater = false; GoogleStyle.IndentCaseLabels = true; GoogleStyle.SpacesBeforeTrailingComments = 2; + GoogleStyle.ObjCSpaceBeforeProtocolList = false; return GoogleStyle; } @@ -974,7 +976,9 @@ private: return Right.is(tok::hash); if (Right.is(tok::r_paren) || Right.is(tok::semi) || Right.is(tok::comma)) return false; - if (Left.is(tok::kw_template) && Right.is(tok::less)) + if (Right.is(tok::less) && + (Left.is(tok::kw_template) || + (CurrentLineType == LT_ObjCDecl && Style.ObjCSpaceBeforeProtocolList))) return true; if (Left.is(tok::arrow) || Right.is(tok::arrow)) return false; diff --git a/clang/test/Index/comment-objc-decls.m b/clang/test/Index/comment-objc-decls.m index 9b9805fb8407..ae3b0bbf415d 100644 --- a/clang/test/Index/comment-objc-decls.m +++ b/clang/test/Index/comment-objc-decls.m @@ -73,7 +73,7 @@ */ @property (copy) id PropertyMyClass; @end -// CHECK: @interface MyClass : NSObject<MyProto> {\n id IvarMyClass;\n}\n@end +// CHECK: @interface MyClass : NSObject <MyProto> {\n id IvarMyClass;\n}\n@end // CHECK: id IvarMyClass // CHECK: - (id)MethodMyClass; // CHECK: + (id)ClassMethodMyClass; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b55cad742eaa..9d29880722da 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1186,7 +1186,7 @@ TEST_F(FormatTest, FormatObjCBlocks) { TEST_F(FormatTest, FormatObjCInterface) { // FIXME: Handle comments like in "@interface /* wait for it */ Foo", PR14875 // FIXME: In google style, it's "+(id) init", not "+ (id)init". - verifyFormat("@interface Foo : NSObject {\n" + verifyFormat("@interface Foo : NSObject {\n" "@public\n" " int field1;\n" "@protected\n" @@ -1199,7 +1199,6 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - // FIXME: In LLVM style, there should be a space before '<' for protocols. verifyGoogleFormat("@interface Foo : NSObject {\n" " @public\n" " int field1;\n" @@ -1228,10 +1227,14 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar\n" + verifyFormat("@interface Foo : Bar \n" "+ (id)init;\n" "@end"); + verifyGoogleFormat("@interface Foo : Bar\n" + "+ (id)init;\n" + "@end"); + verifyFormat("@interface Foo (HackStuff)\n" "+ (id)init;\n" "@end"); @@ -1240,10 +1243,14 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo (HackStuff)\n" + verifyFormat("@interface Foo (HackStuff) \n" "+ (id)init;\n" "@end"); + verifyGoogleFormat("@interface Foo (HackStuff)\n" + "+ (id)init;\n" + "@end"); + verifyFormat("@interface Foo {\n" " int _i;\n" "}\n" @@ -1256,7 +1263,7 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo : Bar {\n" + verifyFormat("@interface Foo : Bar {\n" " int _i;\n" "}\n" "+ (id)init;\n" @@ -1274,7 +1281,7 @@ TEST_F(FormatTest, FormatObjCInterface) { "+ (id)init;\n" "@end"); - verifyFormat("@interface Foo (HackStuff) {\n" + verifyFormat("@interface Foo (HackStuff) {\n" " int _i;\n" "}\n" "+ (id)init;\n" @@ -1351,11 +1358,14 @@ TEST_F(FormatTest, FormatObjCProtocol) { "- (NSUInteger)numberOfThings;\n" "@end"); - // FIXME: In LLVM style, there should be a space before '<' for protocols. - verifyFormat("@protocol MyProtocol\n" + verifyFormat("@protocol MyProtocol \n" "- (NSUInteger)numberOfThings;\n" "@end"); + verifyGoogleFormat("@protocol MyProtocol\n" + "- (NSUInteger)numberOfThings;\n" + "@end"); + verifyFormat("@protocol Foo;\n" "@protocol Bar;\n");