| 1 |
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -verify |
| 2 |
|
| 3 |
#define ASYNC(...) __attribute__((swift_async(__VA_ARGS__))) |
| 4 |
#define ASYNC_ERROR(...) __attribute__((swift_async_error(__VA_ARGS__))) |
| 5 |
|
| 6 |
ASYNC(swift_private, 1) |
| 7 |
ASYNC_ERROR(zero_argument, 1) |
| 8 |
void test_good(void (^handler)(int)); |
| 9 |
|
| 10 |
ASYNC(swift_private, 2) |
| 11 |
ASYNC_ERROR(nonzero_argument, 2) |
| 12 |
void test_good2(double, void (^handler)(double, int, double)); |
| 13 |
|
| 14 |
enum SomeEnum { SE_a, SE_b }; |
| 15 |
|
| 16 |
ASYNC(swift_private, 1) |
| 17 |
ASYNC_ERROR(nonzero_argument, 1) |
| 18 |
void test_good3(void (^handler)(enum SomeEnum, double)); |
| 19 |
|
| 20 |
ASYNC_ERROR(zero_argument, 1) |
| 21 |
ASYNC(swift_private, 1) |
| 22 |
void test_rev_order(void (^handler)(int)); |
| 23 |
|
| 24 |
@class NSError; |
| 25 |
|
| 26 |
ASYNC(swift_private, 1) |
| 27 |
ASYNC_ERROR(nonnull_error) |
| 28 |
void test_nserror(void (^handler)(NSError *)); |
| 29 |
|
| 30 |
typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef; |
| 31 |
|
| 32 |
ASYNC(swift_private, 1) |
| 33 |
ASYNC_ERROR(nonnull_error) |
| 34 |
void test_cferror(void (^handler)(CFErrorRef)); |
| 35 |
|
| 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)); |
| 39 |
|
| 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)); |
| 43 |
|
| 44 |
ASYNC(swift_private, 1) |
| 45 |
ASYNC_ERROR(none) |
| 46 |
void test_none(void (^)(void)); |
| 47 |
|
| 48 |
ASYNC(none) |
| 49 |
ASYNC_ERROR(none) |
| 50 |
void test_double_none(void (^)(void)); |
| 51 |
|
| 52 |
ASYNC(none) |
| 53 |
ASYNC_ERROR(none, 1) // expected-error {{'swift_async_error' attribute takes one argument}} |
| 54 |
void test_double_none_args(void); |
| 55 |
|
| 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)); |
| 59 |
|
| 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)); |
| 63 |
|
| 64 |
ASYNC_ERROR(none) int x; // expected-warning{{'swift_async_error' attribute only applies to functions and Objective-C methods}} |
| 65 |
|
| 66 |
@interface ObjC |
| 67 |
-(void)m1:(void (^)(int))handler |
| 68 |
ASYNC(swift_private, 1) |
| 69 |
ASYNC_ERROR(zero_argument, 1); |
| 70 |
|
| 71 |
-(void)m2:(int)first withSecond:(void (^)(int))handler |
| 72 |
ASYNC(swift_private, 2) |
| 73 |
ASYNC_ERROR(nonzero_argument, 1); |
| 74 |
|
| 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); |
| 78 |
|
| 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'}} |
| 82 |
|
| 83 |
-(void)m5:(void (^)(NSError *))handler |
| 84 |
ASYNC(swift_private, 1) |
| 85 |
ASYNC_ERROR(nonnull_error); |
| 86 |
|
| 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}} |
| 90 |
@end |
| 91 |
|
| 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 **); |
| 97 |
|
| 98 |
@interface TestNoSwiftAsync |
| 99 |
// swift_async_error can make sense without swift_async. |
| 100 |
-(void)doAThingWithCompletion:(void (^)(NSError *))completion |
| 101 |
ASYNC_ERROR(nonnull_error); |
| 102 |
@end |