1 // RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -verify
3 #include "nullability-pragmas-1.h"
4 #include "nullability-pragmas-2.h"
5 #include "nullability-pragmas-generics-1.h"
7 #if !__has_feature(assume_nonnull)
8 # error assume_nonnull feature is not set
11 #if !__has_extension(assume_nonnull)
12 # error assume_nonnull extension is not set
15 void test_pragmas_1(A * _Nonnull a, AA * _Nonnull aa) {
16 f1(0); // okay: no nullability annotations
17 f2(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
18 f3(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
19 f4(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
20 f5(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
21 f6(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
24 f9(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
25 f10(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
28 [a method1:0]; // expected-warning{{null passed to a callee that requires a non-null argument}}
30 f17(a); // expected-error{{no matching function for call to 'f17'}}
31 [a method3: a]; // expected-error{{cannot initialize a parameter of type 'NSError * _Nullable * _Nullable' with an lvalue of type 'A * _Nonnull'}}
32 [a method4: a]; // expected-error{{cannot initialize a parameter of type 'NSErrorPtr _Nullable * _Nullable' (aka 'NSError **') with an lvalue of type 'A * _Nonnull'}}
35 ptr = f13(); // expected-error{{incompatible pointer types assigning to 'float *' from 'int_ptr _Nonnull' (aka 'int *')}}
36 ptr = f14(); // expected-error{{incompatible pointer types assigning to 'float *' from 'A * _Nonnull'}}
37 ptr = [a method1:a]; // expected-error{{incompatible pointer types assigning to 'float *' from 'A * _Nonnull'}}
38 ptr = a.aProp; // expected-error{{incompatible pointer types assigning to 'float *' from 'A * _Nonnull'}}
39 ptr = global_int_ptr; // expected-error{{incompatible pointer types assigning to 'float *' from 'int * _Nonnull'}}
40 ptr = f15(); // expected-error{{incompatible pointer types assigning to 'float *' from 'int * _Null_unspecified'}}
41 ptr = f16(); // expected-error{{incompatible pointer types assigning to 'float *' from 'A * _Null_unspecified'}}
42 ptr = [a method2]; // expected-error{{incompatible pointer types assigning to 'float *' from 'A * _Null_unspecified'}}
44 ptr = aa->ivar1; // expected-error{{incompatible pointer types assigning to 'float *' from 'id'}}
45 ptr = aa->ivar2; // expected-error{{incompatible pointer types assigning to 'float *' from 'id _Nonnull'}}
48 void test_pragmas_generics(void) {
52 fp = [genC tee]; // expected-error{{incompatible pointer types assigning to 'float *' from 'C *'}}
53 fp = [genC maybeTee]; // expected-error{{incompatible pointer types assigning to 'float *' from 'C * _Nullable'}}
56 fp = genC2; // expected-error{{incompatible pointer types assigning to 'float *' from 'Generic_with_C' (aka 'NSGeneric<C *> *')}}