diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-10 01:32:12 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-10 01:32:12 +0000 |
commit | 7bdcc4a9da8ccbafb15872083f551366cdaf3b51 (patch) | |
tree | bb52354737aeaa0e413fe20cb96e321ba9e47aac /clang/test/Parser/objcxx11-attributes.mm | |
parent | 076b3041c0706a957766f7e5e885f05b2eaf255e (diff) | |
download | llvm-7bdcc4a9da8ccbafb15872083f551366cdaf3b51.zip llvm-7bdcc4a9da8ccbafb15872083f551366cdaf3b51.tar.gz llvm-7bdcc4a9da8ccbafb15872083f551366cdaf3b51.tar.bz2 |
Disambiguation of '[[':
* In C++11, '[[' is ill-formed unless it starts an attribute-specifier. Reject
array sizes and array indexes which begin with a lambda-expression. Recover by
parsing the lambda as a lambda.
* In Objective-C++11, either '[' could be the start of a message-send.
Fully disambiguate this case: it turns out that the grammars of message-sends,
lambdas and attributes do not actually overlap. Accept any occurrence of '[['
where either '[' starts a message send, but reject a lambda in an array index
just like in C++11 mode.
Implement a couple of changes to the attribute wording which occurred after our
attributes implementation landed:
* In a function-declaration, the attributes go after the exception specification,
not after the right paren.
* A reference type can have attributes applied.
* An 'identifier' in an attribute can also be a keyword. Support for alternative
tokens (iso646 keywords) in attributes to follow.
And some bug fixes:
* Parse attributes after declarator-ids, even if they are not simple identifiers.
* Do not accept attributes after a parenthesized declarator.
* Accept attributes after an array size in a new-type-id.
* Partially disamiguate 'delete' followed by a lambda. More work is required
here for the case where the lambda-introducer is '[]'.
llvm-svn: 154369
Diffstat (limited to 'clang/test/Parser/objcxx11-attributes.mm')
-rw-r--r-- | clang/test/Parser/objcxx11-attributes.mm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/test/Parser/objcxx11-attributes.mm b/clang/test/Parser/objcxx11-attributes.mm new file mode 100644 index 0000000..719cdcc --- /dev/null +++ b/clang/test/Parser/objcxx11-attributes.mm @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +@interface X {} ++ (X*) alloc; +- (X*) init; +- (int) getSize; +- (void) setSize: (int) size; +- (X*) getSelf; +@end + +void f(X *noreturn) { + // An array size which is computed by a message send is OK. + int a[ [noreturn getSize] ]; + + // ... but is interpreted as an attribute where possible. + int b[ [noreturn] ]; // expected-warning {{'noreturn' only applies to function types}} + + int c[ [noreturn getSize] + 1 ]; + + // An array size which is computed by a lambda is not OK. + int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-warning {{'noreturn' only applies}} + + // A message send which contains a message send is OK. + [ [ X alloc ] init ]; + [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{unused}} + + // A message send which contains a lambda is OK. + [ [noreturn] { return noreturn; } () setSize: 4 ]; + [ [bitand] { return noreturn; } () setSize: 5 ]; + [[[[] { return [ X alloc ]; } () init] getSelf] getSize]; + + // An attribute is OK. + [[]]; + [[int(), noreturn]]; + [[class, test(foo 'x' bar),,,]]; +} + +template<typename...Ts> void f(Ts ...x) { + [[test::foo(bar, baz)...]]; + [[used(x)...]]; + [[x...] { return [ X alloc ]; }() init]; +} |