1 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -verify
3 #define ASYNC(...) __attribute__((swift_async(__VA_ARGS__)))
4 #define ASYNC_ERROR(...) __attribute__((swift_async_error(__VA_ARGS__)))
6 ASYNC(swift_private, 1)
7 ASYNC_ERROR(zero_argument, 1)
8 void test_good(void (^handler)(int));
10 ASYNC(swift_private, 2)
11 ASYNC_ERROR(nonzero_argument, 2)
12 void test_good2(double, void (^handler)(double, int, double));
14 enum SomeEnum { SE_a, SE_b };
16 ASYNC(swift_private, 1)
17 ASYNC_ERROR(nonzero_argument, 1)
18 void test_good3(void (^handler)(enum SomeEnum, double));
20 ASYNC_ERROR(zero_argument, 1)
21 ASYNC(swift_private, 1)
22 void test_rev_order(void (^handler)(int));
26 ASYNC(swift_private, 1)
27 ASYNC_ERROR(nonnull_error)
28 void test_nserror(void (^handler)(NSError *));
30 typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef;
32 ASYNC(swift_private, 1)
33 ASYNC_ERROR(nonnull_error)
34 void test_cferror(void (^handler)(CFErrorRef));
36 ASYNC(swift_private, 1)
37 ASYNC_ERROR(nonnull_error) // expected-error {{'swift_async_error' attribute with 'nonnull_error' convention can only be applied to a function with a completion handler with an error parameter}}
38 void test_interror(void (^handler)(int));
40 ASYNC(swift_private, 1)
41 ASYNC_ERROR(zero_argument, 1) // expected-error {{'swift_async_error' attribute with 'zero_argument' convention must have an integral-typed parameter in completion handler at index 1, type here is 'double'}}
42 void test_not_integral(void (^handler)(double));
44 ASYNC(swift_private, 1)
46 void test_none(void (^)(void));
50 void test_double_none(void (^)(void));
53 ASYNC_ERROR(none, 1) // expected-error {{'swift_async_error' attribute takes one argument}}
54 void test_double_none_args(void);
56 ASYNC(swift_private, 1)
57 ASYNC_ERROR(nonnull_error, 1) // expected-error{{'swift_async_error' attribute takes one argument}}
58 void test_args(void (^)(void));
60 ASYNC(swift_private, 1)
61 ASYNC_ERROR(zero_argument, 1, 1) // expected-error{{'swift_async_error' attribute takes no more than 2 arguments}}
62 void test_args2(void (^)(int));
64 ASYNC_ERROR(none) int x; // expected-warning{{'swift_async_error' attribute only applies to functions and Objective-C methods}}
67 -(void)m1:(void (^)(int))handler
68 ASYNC(swift_private, 1)
69 ASYNC_ERROR(zero_argument, 1);
71 -(void)m2:(int)first withSecond:(void (^)(int))handler
72 ASYNC(swift_private, 2)
73 ASYNC_ERROR(nonzero_argument, 1);
75 -(void)m3:(void (^)(void))block
76 ASYNC_ERROR(zero_argument, 1) // expected-error {{'swift_async_error' attribute parameter 2 is out of bounds}}
77 ASYNC(swift_private, 1);
79 -(void)m4:(void (^)(double, int, float))handler
80 ASYNC(swift_private, 1)
81 ASYNC_ERROR(nonzero_argument, 1); // expected-error{{swift_async_error' attribute with 'nonzero_argument' convention must have an integral-typed parameter in completion handler at index 1, type here is 'double'}}
83 -(void)m5:(void (^)(NSError *))handler
84 ASYNC(swift_private, 1)
85 ASYNC_ERROR(nonnull_error);
87 -(void)m6:(void (^)(void *))handler
88 ASYNC(swift_private, 1)
89 ASYNC_ERROR(nonnull_error); // expected-error{{'swift_async_error' attribute with 'nonnull_error' convention can only be applied to a method with a completion handler with an error parameter}}
92 // 'swift_error' and 'swift_async_error' are OK on one function.
93 ASYNC(swift_private, 1)
94 ASYNC_ERROR(nonnull_error)
95 __attribute__((swift_error(nonnull_error)))
96 void swift_error_and_swift_async_error(void (^handler)(NSError *), NSError **);
98 @interface TestNoSwiftAsync
99 // swift_async_error can make sense without swift_async.
100 -(void)doAThingWithCompletion:(void (^)(NSError *))completion
101 ASYNC_ERROR(nonnull_error);