blob: c1d8c4132dc792c7100e351670a99ffa82d88038 [file] [log] [blame]
Richard Smith6ee326a2012-04-10 01:32:12 +00001// 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
11void 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.
Richard Smithcd8ab512013-01-17 01:30:42 +000016 int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions and methods}}
Richard Smith6ee326a2012-04-10 01:32:12 +000017
18 int c[ [noreturn getSize] + 1 ];
19
20 // An array size which is computed by a lambda is not OK.
Richard Smithcd8ab512013-01-17 01:30:42 +000021 int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies}}
Richard Smith6ee326a2012-04-10 01:32:12 +000022
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 [[]];
Michael Han6880f492012-10-03 01:56:22 +000034 [[int(), noreturn]]; // expected-warning {{unknown attribute 'int' ignored}} \
Richard Smith05321402013-02-19 23:47:15 +000035 // expected-error {{'noreturn' attribute cannot be applied to a statement}}
Michael Han6880f492012-10-03 01:56:22 +000036 [[class, test(foo 'x' bar),,,]]; // expected-warning {{unknown attribute 'test' ignored}}\
37 // expected-warning {{unknown attribute 'class' ignored}}
38
Richard Smith05321402013-02-19 23:47:15 +000039 [[bitand, noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a statement}} \
Michael Han6880f492012-10-03 01:56:22 +000040 expected-warning {{unknown attribute 'bitand' ignored}}
Richard Smith6ce48a72012-04-11 04:01:28 +000041
Richard Smithb9c62612012-07-30 21:30:52 +000042 // FIXME: Suppress vexing parse warning
Richard Smithcd8ab512013-01-17 01:30:42 +000043 [[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smith534986f2012-04-14 00:33:13 +000044 int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
Richard Smith6ce48a72012-04-11 04:01:28 +000045
46 // A function taking a noreturn function.
Richard Smith5c521662013-01-15 02:48:13 +000047 int(f)([[gnu::noreturn]] int ()); // expected-note {{here}}
Richard Smith6ce48a72012-04-11 04:01:28 +000048 f(e);
Richard Smith534986f2012-04-14 00:33:13 +000049 f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}}
Richard Smith6ce48a72012-04-11 04:01:28 +000050
51 // Variables initialized by a message send.
52 int(g)([[noreturn getSelf] getSize]);
53 int(h)([[noreturn]{return noreturn;}() getSize]);
54
55 int i = g + h;
Richard Smith6ee326a2012-04-10 01:32:12 +000056}
57
58template<typename...Ts> void f(Ts ...x) {
Michael Han6880f492012-10-03 01:56:22 +000059 [[test::foo(bar, baz)...]]; // expected-error {{attribute 'foo' cannot be used as an attribute pack}} \
60 // expected-warning {{unknown attribute 'foo' ignored}}
61
62 [[used(x)...]]; // expected-error {{attribute 'used' cannot be used as an attribute pack}} \
63 // expected-warning {{unknown attribute 'used' ignored}}
64
Richard Smith6ee326a2012-04-10 01:32:12 +000065 [[x...] { return [ X alloc ]; }() init];
66}