Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -fsyntax-only -fblocks -I %S/Inputs %s -verify
      2 
      3 #include "nullability-pragmas-1.h"
      4 #include "nullability-pragmas-2.h"
      5 #include "nullability-pragmas-generics-1.h"
      6 
      7 #if !__has_feature(assume_nonnull)
      8 #  error assume_nonnull feature is not set
      9 #endif
     10 
     11 #if !__has_extension(assume_nonnull)
     12 #  error assume_nonnull extension is not set
     13 #endif
     14 
     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}}
     22   f7(0); // okay
     23   f8(0); // okay
     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}}
     26   f11(0); // okay
     27   f12(0); // okay
     28   [a method1:0]; // expected-warning{{null passed to a callee that requires a non-null argument}}
     29 
     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'}}
     33 
     34   float *ptr;
     35   ptr = f13(); // expected-error{{assigning to 'float *' from incompatible type 'int_ptr _Nonnull' (aka 'int *')}}
     36   ptr = f14(); // expected-error{{assigning to 'float *' from incompatible type 'A * _Nonnull'}}
     37   ptr = [a method1:a]; // expected-error{{assigning to 'float *' from incompatible type 'A * _Nonnull'}}
     38   ptr = a.aProp; // expected-error{{assigning to 'float *' from incompatible type 'A * _Nonnull'}}
     39   ptr = global_int_ptr; // expected-error{{assigning to 'float *' from incompatible type 'int * _Nonnull'}}
     40   ptr = f15(); // expected-error{{assigning to 'float *' from incompatible type 'int * _Null_unspecified'}}
     41   ptr = f16(); // expected-error{{assigning to 'float *' from incompatible type 'A * _Null_unspecified'}}
     42   ptr = [a method2]; // expected-error{{assigning to 'float *' from incompatible type 'A * _Null_unspecified'}}
     43 
     44   ptr = aa->ivar1; // expected-error{{from incompatible type 'id'}}
     45   ptr = aa->ivar2; // expected-error{{from incompatible type 'id _Nonnull'}}
     46 }
     47 
     48 void test_pragmas_generics(void) {
     49   float *fp;
     50 
     51   NSGeneric<C *> *genC;
     52   fp = [genC tee]; // expected-error{{from incompatible type 'C *'}}
     53   fp = [genC maybeTee]; // expected-error{{from incompatible type 'C * _Nullable'}}
     54 
     55   Generic_with_C genC2;
     56   fp = genC2; // expected-error{{from incompatible type 'Generic_with_C' (aka 'NSGeneric<C *> *')}}
     57 }
     58