xref: /llvm-project/clang/test/SemaObjC/attr-swift-async.m (revision 22db4824b9e03fe8c2e9217d6832b71ac23c175f)
15a28e1d9SErik Pilkington// RUN: %clang_cc1                 -verify -fsyntax-only -fblocks %s
25a28e1d9SErik Pilkington// RUN: %clang_cc1 -xobjective-c++ -verify -fsyntax-only -fblocks %s
35a28e1d9SErik Pilkington
45a28e1d9SErik Pilkington#define SA(...) __attribute__((swift_async(__VA_ARGS__)))
55a28e1d9SErik Pilkington
65a28e1d9SErik PilkingtonSA(none) int a; // expected-warning{{'swift_async' attribute only applies to functions and Objective-C methods}}
75a28e1d9SErik Pilkington
8*22db4824SAaron BallmanSA(none) void b(void);
95a28e1d9SErik Pilkington
10*22db4824SAaron BallmanSA(not_swift_private, 0) void c(void); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
11*22db4824SAaron BallmanSA(swift_private, 1) void d(void); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
125a28e1d9SErik PilkingtonSA(swift_private, 1) void e(int); // expected-error{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int'}}
13*22db4824SAaron BallmanSA(not_swift_private, 1) void f(int (^)(void)); // expected-error-re{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int (^)({{(void)?}})'}}
14*22db4824SAaron BallmanSA(swift_private, 1) void g(void (^)(void));
155a28e1d9SErik Pilkington
16*22db4824SAaron BallmanSA(none, 1) void h(void); // expected-error{{'swift_async' attribute takes one argument}}
17*22db4824SAaron BallmanSA() void i(void); // expected-error{{'swift_async' attribute takes at least 1 argument}}
18*22db4824SAaron BallmanSA(not_swift_private) void j(void); // expected-error{{'swift_async' attribute requires exactly 2 arguments}}
19*22db4824SAaron BallmanSA(43) void k(void); // expected-error{{'swift_async' attribute requires parameter 1 to be an identifier}}
20*22db4824SAaron BallmanSA(not_a_thing, 0) void l(void); // expected-error{{first argument to 'swift_async' must be either 'none', 'swift_private', or 'not_swift_private'}}
215a28e1d9SErik Pilkington
225a28e1d9SErik Pilkington@interface TestOnMethods
23*22db4824SAaron Ballman-(void)m1:(int (^)(void))callback SA(swift_private, 1); // expected-error-re{{'swift_async' completion handler parameter must have block type returning 'void', type here is 'int (^)({{(void)?}})'}}
24*22db4824SAaron Ballman-(void)m2:(void (^)(void))callback SA(swift_private, 0); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
25*22db4824SAaron Ballman-(void)m3:(void (^)(void))callback SA(swift_private, 2); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
265a28e1d9SErik Pilkington-(void)m4 SA(none);
275a28e1d9SErik Pilkington-(void)m5:(int)p handler:(void (^)(int))callback SA(not_swift_private, 2);
285a28e1d9SErik Pilkington@end
295a28e1d9SErik Pilkington
305a28e1d9SErik Pilkington#ifdef __cplusplus
315a28e1d9SErik Pilkingtonstruct S {
325a28e1d9SErik Pilkington  SA(none) void mf1();
335a28e1d9SErik Pilkington  SA(swift_private, 2) void mf2(void (^)());
345a28e1d9SErik Pilkington  SA(swift_private, 1) void mf3(void (^)()); // expected-error{{'swift_async' attribute is invalid for the implicit this argument}}
355a28e1d9SErik Pilkington  SA(swift_private, 0) void mf4(void (^)()); // expected-error{{'swift_async' attribute parameter 2 is out of bounds}}
365a28e1d9SErik Pilkington  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 (^)()'}}
375a28e1d9SErik Pilkington};
385a28e1d9SErik Pilkington#endif
39