diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/Format.cpp | 13 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 6 |
2 files changed, 9 insertions, 10 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index ac22d6b4501..f7e74abab37 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1514,8 +1514,8 @@ private: "UIView", }; - auto LineContainsObjCCode = [&Keywords](const AnnotatedLine &Line) { - for (const FormatToken *FormatTok = Line.First; FormatTok; + for (auto Line : AnnotatedLines) { + for (const FormatToken *FormatTok = Line->First; FormatTok; FormatTok = FormatTok->Next) { if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) && (FormatTok->isObjCAtKeyword(tok::objc_interface) || @@ -1535,14 +1535,7 @@ private: TT_ObjCMethodSpecifier, TT_ObjCProperty)) { return true; } - } - return false; - }; - for (auto Line : AnnotatedLines) { - if (LineContainsObjCCode(*Line)) - return true; - for (auto ChildLine : Line->Children) { - if (LineContainsObjCCode(*ChildLine)) + if (guessIsObjC(Line->Children, Keywords)) return true; } } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c1250283a13..819ab3c44a5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12159,6 +12159,12 @@ TEST_F(FormatTest, GuessLanguageWithChildLines) { guessLanguage("foo.h", "#define FOO ({ std::string s; })")); EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "#define FOO ({ NSString *s; })")); + EXPECT_EQ( + FormatStyle::LK_Cpp, + guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })")); + EXPECT_EQ( + FormatStyle::LK_ObjC, + guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })")); } } // end namespace |