1 | __attribute__((objc_root_class)) |
2 | @interface NSError |
3 | @end |
4 | |
5 | __attribute__((objc_root_class)) |
6 | @interface A |
7 | @end |
8 | |
9 | struct X { }; |
10 | |
11 | void f1(int *x); // expected-warning{{pointer is missing a nullability type specifier}} |
12 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
13 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
14 | |
15 | typedef struct __attribute__((objc_bridge(NSError))) __CFError *CFErrorRef; |
16 | typedef NSError *NSErrorPtr; |
17 | typedef NSError **NSErrorPtrPtr; |
18 | typedef CFErrorRef *CFErrorRefPtr; |
19 | typedef int *int_ptr; |
20 | typedef A *A_ptr; |
21 | typedef int (^block_ptr)(int, int); |
22 | |
23 | #pragma clang assume_nonnull begin |
24 | |
25 | void f2(int *x); |
26 | void f3(A* obj); |
27 | void f4(int (^block)(int, int)); |
28 | void f5(int_ptr x); |
29 | void f6(A_ptr obj); |
30 | void f7(int * _Nullable x); |
31 | void f8(A * _Nullable obj); |
32 | void f9(int X::* mem_ptr); |
33 | void f10(int (X::*mem_func)(int, int)); |
34 | void f11(int X::* _Nullable mem_ptr); |
35 | void f12(int (X::* _Nullable mem_func)(int, int)); |
36 | |
37 | int_ptr f13(void); |
38 | A *f14(void); |
39 | |
40 | int * _Null_unspecified f15(void); |
41 | A * _Null_unspecified f16(void); |
42 | void f17(CFErrorRef *error); // expected-note{{no known conversion from 'A * _Nonnull' to 'CFErrorRef _Nullable * _Nullable' (aka '__CFError **') for 1st argument}} |
43 | void f18(A **); // expected-warning 2{{pointer is missing a nullability type specifier}} |
44 | // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} |
45 | // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} |
46 | void f19(CFErrorRefPtr error); // expected-warning{{pointer is missing a nullability type specifier}} |
47 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
48 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
49 | |
50 | void g1(int (^)(int, int)); |
51 | void g2(int (^ *bp)(int, int)); // expected-warning{{block pointer is missing a nullability type specifier}} |
52 | // expected-note@-1{{insert '_Nullable' if the block pointer may be null}} |
53 | // expected-note@-2{{insert '_Nonnull' if the block pointer should never be null}} |
54 | // expected-warning@-3{{pointer is missing a nullability type specifier}} |
55 | // expected-note@-4{{insert '_Nullable' if the pointer may be null}} |
56 | // expected-note@-5{{insert '_Nonnull' if the pointer should never be null}} |
57 | void g3(block_ptr *bp); // expected-warning{{block pointer is missing a nullability type specifier}} |
58 | // expected-note@-1{{insert '_Nullable' if the block pointer may be null}} |
59 | // expected-note@-2{{insert '_Nonnull' if the block pointer should never be null}} |
60 | // expected-warning@-3{{pointer is missing a nullability type specifier}} |
61 | // expected-note@-4{{insert '_Nullable' if the pointer may be null}} |
62 | // expected-note@-5{{insert '_Nonnull' if the pointer should never be null}} |
63 | void g4(int (*fp)(int, int)); |
64 | void g5(int (**fp)(int, int)); // expected-warning 2{{pointer is missing a nullability type specifier}} |
65 | // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} |
66 | // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} |
67 | |
68 | @interface A(Pragmas1) |
69 | + (instancetype)aWithA:(A *)a; |
70 | - (A *)method1:(A_ptr)ptr; |
71 | - (null_unspecified A *)method2; |
72 | - (void)method3:(NSError **)error; // expected-note{{passing argument to parameter 'error' here}} |
73 | - (void)method4:(NSErrorPtr *)error; // expected-note{{passing argument to parameter 'error' here}} |
74 | - (void)method5:(NSErrorPtrPtr)error; |
75 | // expected-warning@-1{{pointer is missing a nullability type specifier}} |
76 | // expected-note@-2{{insert '_Nullable' if the pointer may be null}} |
77 | // expected-note@-3{{insert '_Nonnull' if the pointer should never be null}} |
78 | |
79 | @property A *aProp; |
80 | @property NSError **anError; // expected-warning 2{{pointer is missing a nullability type specifier}} |
81 | // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} |
82 | // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} |
83 | @end |
84 | |
85 | int *global_int_ptr; |
86 | |
87 | // typedefs not inferred _Nonnull |
88 | typedef int *int_ptr_2; |
89 | |
90 | typedef int * // expected-warning{{pointer is missing a nullability type specifier}} |
91 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
92 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
93 | *int_ptr_ptr; |
94 | |
95 | static inline void f30(void) { |
96 | float *fp = global_int_ptr; // expected-error{{cannot initialize a variable of type 'float *' with an lvalue of type 'int * _Nonnull'}} |
97 | |
98 | int_ptr_2 ip2; |
99 | float *fp2 = ip2; // expected-error{{cannot initialize a variable of type 'float *' with an lvalue of type 'int_ptr_2' (aka 'int *')}} |
100 | |
101 | int_ptr_ptr ipp; |
102 | float *fp3 = ipp; // expected-error{{lvalue of type 'int_ptr_ptr' (aka 'int **')}} |
103 | } |
104 | |
105 | @interface AA : A { |
106 | @public |
107 | id ivar1; |
108 | _Nonnull id ivar2; |
109 | } |
110 | @end |
111 | |
112 | #pragma clang assume_nonnull end |
113 | |
114 | void f20(A *a); // expected-warning{{pointer is missing a nullability type specifier}} |
115 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
116 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
117 | void f21(int_ptr x); // expected-warning{{pointer is missing a nullability type specifier}} |
118 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
119 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
120 | void f22(A_ptr y); // expected-warning{{pointer is missing a nullability type specifier}} |
121 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
122 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
123 | void f23(int_ptr _Nullable x); |
124 | void f24(A_ptr _Nullable y); |
125 | void f25(int_ptr_2 x); // expected-warning{{pointer is missing a nullability type specifier}} |
126 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
127 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
128 | |
129 | @interface A(OutsidePragmas1) |
130 | + (instancetype)aWithInt:(int)value; // expected-warning{{pointer is missing a nullability type specifier}} |
131 | // expected-note@-1{{insert '_Nullable' if the pointer may be null}} |
132 | // expected-note@-2{{insert '_Nonnull' if the pointer should never be null}} |
133 | @end |
134 | |