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