diff options
author | Alex Lorenz <arphaman@gmail.com> | 2019-01-24 23:07:58 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2019-01-24 23:07:58 +0000 |
commit | 9d53cb8f83bf40993bd90405242f62d7e7b380ce (patch) | |
tree | fd6afa1da635a78d8ba74b9f7af6f90709bf5404 /clang/unittests/Format/FormatTestObjC.cpp | |
parent | 76c40f827dfd67cad6bfe477071af2a63ee5505e (diff) | |
download | bcm5719-llvm-9d53cb8f83bf40993bd90405242f62d7e7b380ce.tar.gz bcm5719-llvm-9d53cb8f83bf40993bd90405242f62d7e7b380ce.zip |
[clang-format] square parens with one token are not Objective-C message sends
The commit r322690 introduced support for ObjC detection in header files.
Unfortunately some C headers that use designated initializers are now
incorrectly detected as Objective-C.
This commit fixes it by ensuring that `[ token ]` is not annotated as an
Objective-C message send.
rdar://45504376
Differential Revision: https://reviews.llvm.org/D56226
llvm-svn: 352125
Diffstat (limited to 'clang/unittests/Format/FormatTestObjC.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestObjC.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 2cb3f9f111e..0d3a5d85bb7 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -165,6 +165,20 @@ TEST(FormatTestObjCStyle, DetectsObjCInHeaders) { EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); } +TEST(FormatTestObjCStyle, AvoidDetectingDesignatedInitializersAsObjCInHeaders) { + auto Style = getStyle("LLVM", "a.h", "none", + "static const char *names[] = {[0] = \"foo\",\n" + "[kBar] = \"bar\"};"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); + + Style = getStyle("LLVM", "a.h", "none", + "static const char *names[] = {[0] EQ \"foo\",\n" + "[kBar] EQ \"bar\"};"); + ASSERT_TRUE((bool)Style); + EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); +} + TEST_F(FormatTestObjC, FormatObjCTryCatch) { verifyFormat("@try {\n" " f();\n" |