1// RUN: %clang_cc1                 -verify -fsyntax-only -fblocks %s
2// RUN: %clang_cc1 -xobjective-c++ -verify -fsyntax-only -fblocks %s
3
4#define SA(...) __attribute__((swift_async(__VA_ARGS__)))
5
6SA(none) int a; // expected-warning{{'swift_async' attribute only applies to functions and Objective-C methods}}
7
8SA(none) void b();
9
10SA(not_swift_private, 0) void c(); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
11SA(swift_private, 1) void d(); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
12SA(swift_private, 1) void e(int); // expected-error{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int'}}
13SA(not_swift_private, 1) void f(int (^)()); // expected-error{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int (^)()'}}
14SA(swift_private, 1) void g(void (^)());
15
16SA(none, 1) void h(); // expected-error{{'swift_async' attribute takes one argument}}
17SA() void i(); // expected-error{{'swift_async' attribute takes at least 1 argument}}
18SA(not_swift_private) void j(); // expected-error{{'swift_async' attribute requires exactly 2 arguments}}
19SA(43) void k(); // expected-error{{'swift_async' attribute requires parameter 1 to be an identifier}}
20SA(not_a_thing, 0) void l(); // expected-error{{first argument to 'swift_async' must be either 'none', 'swift_private', or 'not_swift_private'}}
21
22@interface TestOnMethods
23-(void)m1:(int (^)())callback SA(swift_private, 1); // expected-error{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int (^)()'}}
24-(void)m2:(void (^)())callback SA(swift_private, 0); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
25-(void)m3:(void (^)())callback SA(swift_private, 2); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
26-(void)m4 SA(none);
27-(void)m5:(int)p handler:(void (^)(int))callback SA(not_swift_private, 2);
28@end
29
30#ifdef __cplusplus
31struct S {
32  SA(none) void mf1();
33  SA(swift_private, 2) void mf2(void (^)());
34  SA(swift_private, 1) void mf3(void (^)()); // expected-error{{'swift_async' attribute is invalid for the implicit this argument}}
35  SA(swift_private, 0) void mf4(void (^)()); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
36  SA(not_swift_private, 2) void mf5(int (^)()); // expected-error{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int (^)()'}}
37};
38#endif
39