1 #include <stdarg.h> 2 3 void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]); 4 #if ARRAYS_CHECKED 5 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 6 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 7 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 8 #endif 9 10 int *secondThingInTheFileThatNeedsNullabilityIsAPointer; 11 #if !ARRAYS_CHECKED 12 // expected-warning@-2 {{pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}} 13 // expected-note@-3 {{insert '_Nullable' if the pointer may be null}} 14 // expected-note@-4 {{insert '_Nonnull' if the pointer should never be null}} 15 #endif 16 17 int *_Nonnull triggerConsistencyWarnings; 18 19 void test( 20 int ints[], 21 #if ARRAYS_CHECKED 22 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 23 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 24 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 25 #endif 26 void *ptrs[], // expected-warning {{pointer is missing a nullability type specifier}} 27 // expected-note@-1 {{insert '_Nullable' if the pointer may be null}} 28 // expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}} 29 #if ARRAYS_CHECKED 30 // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 31 // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 32 // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 33 #endif 34 void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 35 // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 36 // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 37 #if ARRAYS_CHECKED 38 // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 39 // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 40 // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 41 #endif 42 43 void testArraysOK( 44 int ints[_Nonnull], 45 void *ptrs[_Nonnull], // expected-warning {{pointer is missing a nullability type specifier}} 46 // expected-note@-1 {{insert '_Nullable' if the pointer may be null}} 47 // expected-note@-2 {{insert '_Nonnull' if the pointer should never be null}} 48 void **nestedPtrs[_Nonnull]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 49 // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 50 // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 51 void testAllOK( 52 int ints[_Nonnull], 53 void * _Nullable ptrs[_Nonnull], 54 void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 55 56 void testVAList(va_list ok); // no warning 57 58 #if __cplusplus 59 // Carefully construct a test case such that if a platform's va_list is an array 60 // or pointer type, it gets tested, but otherwise it does not. 61 template<class T, class F> 62 struct pointer_like_or { typedef F type; }; 63 template<class T, class F> 64 struct pointer_like_or<T*, F> { typedef T *type; }; 65 template<class T, class F> 66 struct pointer_like_or<T* const, F> { typedef T * const type; }; 67 template<class T, class F> 68 struct pointer_like_or<T[], F> { typedef T type[]; }; 69 template<class T, class F, unsigned size> 70 struct pointer_like_or<T[size], F> { typedef T type[size]; }; 71 72 void testVAListWithNullability( 73 pointer_like_or<va_list, void*>::type _Nonnull x); // no errors 74 #endif 75 76 void nestedArrays(int x[5][1]) {} 77 #if ARRAYS_CHECKED 78 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 79 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 80 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 81 #endif 82 void nestedArraysOK(int x[_Nonnull 5][1]) {} 83 84 #if !__cplusplus 85 void staticOK(int x[static 5][1]){} 86 #endif 87 88 int globalArraysDoNotNeedNullability[5]; 89 90 typedef int INTS[4]; 91 92 void typedefTest( 93 INTS x, 94 #if ARRAYS_CHECKED 95 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 96 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 97 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 98 #endif 99 INTS _Nonnull x2, 100 _Nonnull INTS x3, 101 INTS y[2], 102 #if ARRAYS_CHECKED 103 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 104 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 105 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 106 #endif 107 INTS y2[_Nonnull 2]); 108 109 110 #pragma clang assume_nonnull begin 111 void testAssumeNonnull( 112 int ints[], 113 #if ARRAYS_CHECKED 114 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 115 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 116 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 117 #endif 118 void *ptrs[], 119 #if ARRAYS_CHECKED 120 // expected-warning@-2 {{array parameter is missing a nullability type specifier}} 121 // expected-note@-3 {{insert '_Nullable' if the array parameter may be null}} 122 // expected-note@-4 {{insert '_Nonnull' if the array parameter should never be null}} 123 #endif 124 void **nestedPtrs[]); // expected-warning 2 {{pointer is missing a nullability type specifier}} 125 // expected-note@-1 2 {{insert '_Nullable' if the pointer may be null}} 126 // expected-note@-2 2 {{insert '_Nonnull' if the pointer should never be null}} 127 #if ARRAYS_CHECKED 128 // expected-warning@-4 {{array parameter is missing a nullability type specifier}} 129 // expected-note@-5 {{insert '_Nullable' if the array parameter may be null}} 130 // expected-note@-6 {{insert '_Nonnull' if the array parameter should never be null}} 131 #endif 132 133 void testAssumeNonnullAllOK( 134 int ints[_Nonnull], 135 void * _Nullable ptrs[_Nonnull], 136 void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 137 void testAssumeNonnullAllOK2( 138 int ints[_Nonnull], 139 void * ptrs[_Nonnull], // backwards-compatibility 140 void * _Nullable * _Nullable nestedPtrs[_Nonnull]); 141 #pragma clang assume_nonnull end 142