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/lib | |
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/lib')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bd824f1e17b..1c93c8c6ccd 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -494,9 +494,14 @@ private: if (CurrentToken->is(tok::r_square)) { if (IsCpp11AttributeSpecifier) CurrentToken->Type = TT_AttributeSquare; - else if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) && + else if (((CurrentToken->Next && + CurrentToken->Next->is(tok::l_paren)) || + (CurrentToken->Previous && + CurrentToken->Previous->Previous == Left)) && Left->is(TT_ObjCMethodExpr)) { - // An ObjC method call is rarely followed by an open parenthesis. + // An ObjC method call is rarely followed by an open parenthesis. It + // also can't be composed of just one token, unless it's a macro that + // will be expanded to more tokens. // FIXME: Do we incorrectly label ":" with this? StartsObjCMethodExpr = false; Left->Type = TT_Unknown; |