xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/objcxx11-attributes.mm (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc@interface X {}
4f4a2713aSLionel Sambuc+ (X*) alloc;
5f4a2713aSLionel Sambuc- (X*) init;
6f4a2713aSLionel Sambuc- (int) getSize;
7f4a2713aSLionel Sambuc- (void) setSize: (int) size;
8f4a2713aSLionel Sambuc- (X*) getSelf;
9f4a2713aSLionel Sambuc@end
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambucvoid f(X *noreturn) {
12f4a2713aSLionel Sambuc  // An array size which is computed by a message send is OK.
13f4a2713aSLionel Sambuc  int a[ [noreturn getSize] ];
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc  // ... but is interpreted as an attribute where possible.
16*0a6a1f1dSLionel Sambuc  int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions}}
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc  int c[ [noreturn getSize] + 1 ];
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc  // An array size which is computed by a lambda is not OK.
21*0a6a1f1dSLionel Sambuc  int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies to functions}}
22f4a2713aSLionel Sambuc
23f4a2713aSLionel Sambuc  // A message send which contains a message send is OK.
24f4a2713aSLionel Sambuc  [ [ X alloc ] init ];
25f4a2713aSLionel Sambuc  [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{unused}}
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc  // A message send which contains a lambda is OK.
28f4a2713aSLionel Sambuc  [ [noreturn] { return noreturn; } () setSize: 4 ];
29f4a2713aSLionel Sambuc  [ [bitand] { return noreturn; } () setSize: 5 ];
30f4a2713aSLionel Sambuc  [[[[] { return [ X alloc ]; } () init] getSelf] getSize];
31f4a2713aSLionel Sambuc
32f4a2713aSLionel Sambuc  // An attribute is OK.
33f4a2713aSLionel Sambuc  [[]];
34f4a2713aSLionel Sambuc  [[int(), noreturn]]; // expected-warning {{unknown attribute 'int' ignored}} \
35f4a2713aSLionel Sambuc  // expected-error {{'noreturn' attribute cannot be applied to a statement}}
36f4a2713aSLionel Sambuc  [[class, test(foo 'x' bar),,,]]; // expected-warning {{unknown attribute 'test' ignored}}\
37f4a2713aSLionel Sambuc  // expected-warning {{unknown attribute 'class' ignored}}
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc  [[bitand, noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a statement}} \
40f4a2713aSLionel Sambuc  expected-warning {{unknown attribute 'bitand' ignored}}
41f4a2713aSLionel Sambuc
42f4a2713aSLionel Sambuc  // FIXME: Suppress vexing parse warning
43f4a2713aSLionel Sambuc  [[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
44f4a2713aSLionel Sambuc  int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc  // A function taking a noreturn function.
47f4a2713aSLionel Sambuc  int(f)([[gnu::noreturn]] int ()); // expected-note {{here}}
48f4a2713aSLionel Sambuc  f(e);
49f4a2713aSLionel Sambuc  f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}}
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc  // Variables initialized by a message send.
52f4a2713aSLionel Sambuc  int(g)([[noreturn getSelf] getSize]);
53f4a2713aSLionel Sambuc  int(h)([[noreturn]{return noreturn;}() getSize]);
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambuc  int i = g + h;
56f4a2713aSLionel Sambuc}
57f4a2713aSLionel Sambuc
58f4a2713aSLionel Sambuctemplate<typename...Ts> void f(Ts ...x) {
59f4a2713aSLionel Sambuc  [[test::foo(bar, baz)...]]; // expected-error {{attribute 'foo' cannot be used as an attribute pack}} \
60f4a2713aSLionel Sambuc  // expected-warning {{unknown attribute 'foo' ignored}}
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc  [[used(x)...]]; // expected-error {{attribute 'used' cannot be used as an attribute pack}} \
63f4a2713aSLionel Sambuc  // expected-warning {{unknown attribute 'used' ignored}}
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambuc  [[x...] { return [ X alloc ]; }() init];
66f4a2713aSLionel Sambuc}
67