diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2687,6 +2687,7 @@ "CGSizeMake", "CGVector", "CGVectorMake", + "FOUNDATION_EXTERN", "NSAffineTransform", "NSArray", "NSAttributedString", @@ -2743,6 +2744,7 @@ "NSURLQueryItem", "NSUUID", "NSValue", + "NS_ASSUME_NONNULL_BEGIN", "UIImage", "UIView", }; diff --git a/clang/test/Format/dump-config-objc-macros.h b/clang/test/Format/dump-config-objc-macros.h new file mode 100644 --- /dev/null +++ b/clang/test/Format/dump-config-objc-macros.h @@ -0,0 +1,8 @@ +// RUN: clang-format -dump-config %s | FileCheck %s + +// CHECK: Language: ObjC +NS_ASSUME_NONNULL_BEGIN + +FOUNDATION_EXTERN int kConstant; + +NS_ASSUME_NONNULL_END diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -94,6 +94,20 @@ ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + Style = getStyle("{}", "a.h", "none", R"objc( +NS_ASSUME_NONNULL_BEGIN +extern int i; +NS_ASSUME_NONNULL_END +)objc"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + + Style = getStyle("{}", "a.h", "none", R"objc( +FOUNDATION_EXTERN void DoStuff(void); +)objc"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); + Style = getStyle("{}", "a.h", "none", "enum Foo {};"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);