2012-04-10 09:32:12 +08:00
|
|
|
// 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.
|
2013-01-17 09:30:42 +08:00
|
|
|
int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions and methods}}
|
2012-04-10 09:32:12 +08:00
|
|
|
|
|
|
|
int c[ [noreturn getSize] + 1 ];
|
|
|
|
|
|
|
|
// An array size which is computed by a lambda is not OK.
|
2013-01-17 09:30:42 +08:00
|
|
|
int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies}}
|
2012-04-10 09:32:12 +08:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
[[]];
|
2012-10-03 09:56:22 +08:00
|
|
|
[[int(), noreturn]]; // expected-warning {{unknown attribute 'int' ignored}} \
|
2013-02-20 07:47:15 +08:00
|
|
|
// expected-error {{'noreturn' attribute cannot be applied to a statement}}
|
2012-10-03 09:56:22 +08:00
|
|
|
[[class, test(foo 'x' bar),,,]]; // expected-warning {{unknown attribute 'test' ignored}}\
|
|
|
|
// expected-warning {{unknown attribute 'class' ignored}}
|
|
|
|
|
2013-02-20 07:47:15 +08:00
|
|
|
[[bitand, noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to a statement}} \
|
2012-10-03 09:56:22 +08:00
|
|
|
expected-warning {{unknown attribute 'bitand' ignored}}
|
2012-04-11 12:01:28 +08:00
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// FIXME: Suppress vexing parse warning
|
2013-01-17 09:30:42 +08:00
|
|
|
[[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
2012-04-14 08:33:13 +08:00
|
|
|
int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
|
2012-04-11 12:01:28 +08:00
|
|
|
|
|
|
|
// A function taking a noreturn function.
|
2013-01-15 10:48:13 +08:00
|
|
|
int(f)([[gnu::noreturn]] int ()); // expected-note {{here}}
|
2012-04-11 12:01:28 +08:00
|
|
|
f(e);
|
2012-04-14 08:33:13 +08:00
|
|
|
f(e2); // expected-error {{cannot initialize a parameter of type 'int (*)() __attribute__((noreturn))' with an lvalue of type 'int ()'}}
|
2012-04-11 12:01:28 +08:00
|
|
|
|
|
|
|
// Variables initialized by a message send.
|
|
|
|
int(g)([[noreturn getSelf] getSize]);
|
|
|
|
int(h)([[noreturn]{return noreturn;}() getSize]);
|
|
|
|
|
|
|
|
int i = g + h;
|
2012-04-10 09:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename...Ts> void f(Ts ...x) {
|
2012-10-03 09:56:22 +08:00
|
|
|
[[test::foo(bar, baz)...]]; // expected-error {{attribute 'foo' cannot be used as an attribute pack}} \
|
|
|
|
// expected-warning {{unknown attribute 'foo' ignored}}
|
|
|
|
|
|
|
|
[[used(x)...]]; // expected-error {{attribute 'used' cannot be used as an attribute pack}} \
|
|
|
|
// expected-warning {{unknown attribute 'used' ignored}}
|
|
|
|
|
2012-04-10 09:32:12 +08:00
|
|
|
[[x...] { return [ X alloc ]; }() init];
|
|
|
|
}
|