diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2018-08-21 16:47:04 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2018-08-21 16:47:04 +0000 |
commit | c6781383495b622f1ad6d3d5346663b265a803be (patch) | |
tree | 5592e02a87e4fcf779fd9e932aeb765042bf13de | |
parent | dbe4e9e3ff4395366da0c998650bf824b11a3a47 (diff) | |
download | bcm5719-llvm-c6781383495b622f1ad6d3d5346663b265a803be.tar.gz bcm5719-llvm-c6781383495b622f1ad6d3d5346663b265a803be.zip |
[Parser] Support alternative operator token keyword args in Objective-C++
rdar://30741878
Differential revision: https://reviews.llvm.org/D50527
llvm-svn: 340301
-rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 13 | ||||
-rw-r--r-- | clang/test/Parser/message-expr-alt-op.mm | 41 |
2 files changed, 54 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 79f826653eb..d1d8507af8c 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -315,6 +315,19 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { return LHS; } + // In Objective-C++, alternative operator tokens can be used as keyword args + // in message expressions. Unconsume the token so that it can reinterpreted + // as an identifier in ParseObjCMessageExpressionBody. i.e., we support: + // [foo meth:0 and:0]; + // [foo not_eq]; + if (getLangOpts().ObjC1 && getLangOpts().CPlusPlus && + Tok.isOneOf(tok::colon, tok::r_square) && + OpToken.getIdentifierInfo() != nullptr) { + PP.EnterToken(Tok); + Tok = OpToken; + return LHS; + } + // Special case handling for the ternary operator. ExprResult TernaryMiddle(true); if (NextTokPrec == prec::Conditional) { diff --git a/clang/test/Parser/message-expr-alt-op.mm b/clang/test/Parser/message-expr-alt-op.mm new file mode 100644 index 00000000000..4fbea575370 --- /dev/null +++ b/clang/test/Parser/message-expr-alt-op.mm @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface WeirdInterface +-(void)allOfThem:(int)a + and:(int)b + and_eq:(int)c + bitand:(int)d + bitor:(int)e + compl:(int)f + not:(int)g + not_eq:(int)h + or:(int)i + or_eq:(int)j + xor:(int)k + xor_eq:(int)l; + +-(void)justAnd:(int)x and:(int)y; +-(void)and; +-(void)and:(int)x; +@end + +void call_it(WeirdInterface *x) { + [x allOfThem:0 + and:0 + and_eq:0 + bitand:0 + bitor:0 + compl:0 + not:0 + not_eq:0 + or:0 + or_eq:0 + xor:0 + xor_eq:0]; + + [x and]; + [x and:0]; + [x &&:0]; // expected-error{{expected expression}}; + [x justAnd:0 and:1]; + [x and: 0 ? : 1]; +} |