Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1440,7 +1440,9 @@ "NSAffineTransform", "NSArray", "NSAttributedString", + "NSBundle", "NSCache", + "NSCalendar", "NSCharacterSet", "NSCountedSet", "NSData", @@ -1466,6 +1468,7 @@ "NSMutableString", "NSNumber", "NSNumberFormatter", + "NSObject", "NSOrderedSet", "NSPoint", "NSPointerArray", @@ -1475,17 +1478,19 @@ "NSSet", "NSSize", "NSString", + "NSTimeZone", "NSUInteger", "NSURL", "NSURLComponents", "NSURLQueryItem", "NSUUID", + "NSValue", }; for (auto &Line : AnnotatedLines) { - for (FormatToken *FormatTok = Line->First->Next; FormatTok; + for (FormatToken *FormatTok = Line->First; FormatTok; FormatTok = FormatTok->Next) { - if ((FormatTok->Previous->is(tok::at) && + if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) && (FormatTok->isObjCAtKeyword(tok::objc_interface) || FormatTok->isObjCAtKeyword(tok::objc_implementation) || FormatTok->isObjCAtKeyword(tok::objc_protocol) || Index: unittests/Format/FormatTestObjC.cpp =================================================================== --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -113,10 +113,6 @@ ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); - Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n"); - ASSERT_TRUE((bool)Style); - EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n"); ASSERT_TRUE((bool)Style); @@ -126,10 +122,6 @@ ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); - Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n"); - ASSERT_TRUE((bool)Style); - EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n"); ASSERT_TRUE((bool)Style); @@ -154,6 +146,23 @@ "inline void Foo() { int foo[] = {1, 2, 3}; }\n"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); + + // ObjC characteristic types. + Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + + Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + + Style = getStyle("{}", "a.h", "none", "NSObject *Foo();\n"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + + Style = getStyle("{}", "a.h", "none", "NSSet *Foo();\n"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); } TEST_F(FormatTestObjC, FormatObjCTryCatch) {