diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3578162c3f6..7e3ef75d3dc 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -313,9 +313,11 @@ private: switch (Tok->FormatTok.Tok.getKind()) { case tok::plus: case tok::minus: - // At the start of the line, +/- specific ObjectiveC method - // declarations. - if (Tok->Parent == NULL) + // At the start of the line, +/- specify ObjectiveC method declarations. + if (Tok->Children.empty() || Tok->Children[0].Children.empty()) + break; // Can't be an ObjectiveC method declaration. + if (Tok->Parent == NULL && (Tok->Children[0].is(tok::l_paren) || + Tok->Children[0].Children[0].is(tok::colon))) Tok->Type = TT_ObjCMethodSpecifier; break; case tok::colon: diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index dc77c77e450..051deebc091 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2067,6 +2067,8 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) { "case -1:\n" " break;\n" "}"); + verifyFormat("#define X -1"); + verifyFormat("#define X -kConstant"); verifyFormat("const NSPoint kBrowserFrameViewPatternOffset = { -5, +3 };"); verifyFormat("const NSPoint kBrowserFrameViewPatternOffset = { +5, -3 };"); |

