Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 | |
| 3 | @interface X {} |
| 4 | + (X*) alloc; |
| 5 | - (X*) init; |
| 6 | - (int) getSize; |
| 7 | - (void) setSize: (int) size; |
| 8 | - (X*) getSelf; |
| 9 | @end |
| 10 | |
| 11 | void f(X *noreturn) { |
| 12 | // An array size which is computed by a message send is OK. |
| 13 | int a[ [noreturn getSize] ]; |
| 14 | |
| 15 | // ... but is interpreted as an attribute where possible. |
| 16 | int b[ [noreturn] ]; // expected-warning {{'noreturn' only applies to function types}} |
| 17 | |
| 18 | int c[ [noreturn getSize] + 1 ]; |
| 19 | |
| 20 | // An array size which is computed by a lambda is not OK. |
| 21 | int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-warning {{'noreturn' only applies}} |
| 22 | |
| 23 | // A message send which contains a message send is OK. |
| 24 | [ [ X alloc ] init ]; |
| 25 | [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{unused}} |
| 26 | |
| 27 | // A message send which contains a lambda is OK. |
| 28 | [ [noreturn] { return noreturn; } () setSize: 4 ]; |
| 29 | [ [bitand] { return noreturn; } () setSize: 5 ]; |
| 30 | [[[[] { return [ X alloc ]; } () init] getSelf] getSize]; |
| 31 | |
| 32 | // An attribute is OK. |
| 33 | [[]]; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 34 | [[int(), noreturn]]; // expected-warning {{attribute noreturn cannot be specified on a statement}} |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 35 | [[class, test(foo 'x' bar),,,]]; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 36 | [[bitand, noreturn]]; // expected-warning {{attribute noreturn cannot be specified on a statement}} |
Richard Smith | 6ce48a7 | 2012-04-11 04:01:28 +0000 | [diff] [blame] | 37 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 38 | // FIXME: Suppress vexing parse warning |
| 39 | [[noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 40 | int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}} |
Richard Smith | 6ce48a7 | 2012-04-11 04:01:28 +0000 | [diff] [blame] | 41 | |
| 42 | // A function taking a noreturn function. |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 43 | int(f)([[noreturn]] int()); // expected-note {{here}} |
Richard Smith | 6ce48a7 | 2012-04-11 04:01:28 +0000 | [diff] [blame] | 44 | f(e); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 45 | f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}} |
Richard Smith | 6ce48a7 | 2012-04-11 04:01:28 +0000 | [diff] [blame] | 46 | |
| 47 | // Variables initialized by a message send. |
| 48 | int(g)([[noreturn getSelf] getSize]); |
| 49 | int(h)([[noreturn]{return noreturn;}() getSize]); |
| 50 | |
| 51 | int i = g + h; |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | template<typename...Ts> void f(Ts ...x) { |
| 55 | [[test::foo(bar, baz)...]]; |
| 56 | [[used(x)...]]; |
| 57 | [[x...] { return [ X alloc ]; }() init]; |
| 58 | } |