142 lines · c
1#include <stdarg.h>2 3void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]);4#if ARRAYS_CHECKED5// 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#endif9 10int *secondThingInTheFileThatNeedsNullabilityIsAPointer;11#if !ARRAYS_CHECKED12// 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#endif16 17int *_Nonnull triggerConsistencyWarnings;18 19void test(20 int ints[],21#if ARRAYS_CHECKED22// 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#endif26 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_CHECKED30// 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#endif34 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_CHECKED38// 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#endif42 43void 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}}51void testAllOK(52 int ints[_Nonnull],53 void * _Nullable ptrs[_Nonnull],54 void * _Nullable * _Nullable nestedPtrs[_Nonnull]);55 56void testVAList(va_list ok); // no warning57 58#if __cplusplus59// Carefully construct a test case such that if a platform's va_list is an array60// or pointer type, it gets tested, but otherwise it does not.61template<class T, class F>62struct pointer_like_or { typedef F type; };63template<class T, class F>64struct pointer_like_or<T*, F> { typedef T *type; };65template<class T, class F>66struct pointer_like_or<T* const, F> { typedef T * const type; };67template<class T, class F>68struct pointer_like_or<T[], F> { typedef T type[]; };69template<class T, class F, unsigned size>70struct pointer_like_or<T[size], F> { typedef T type[size]; };71 72void testVAListWithNullability(73 pointer_like_or<va_list, void*>::type _Nonnull x); // no errors74#endif75 76void nestedArrays(int x[5][1]) {}77#if ARRAYS_CHECKED78// 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#endif82void nestedArraysOK(int x[_Nonnull 5][1]) {}83 84#if !__cplusplus85void staticOK(int x[static 5][1]){}86#endif87 88int globalArraysDoNotNeedNullability[5];89 90typedef int INTS[4];91 92void typedefTest(93 INTS x,94#if ARRAYS_CHECKED95// 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#endif99 INTS _Nonnull x2,100 _Nonnull INTS x3,101 INTS y[2],102#if ARRAYS_CHECKED103// 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#endif107 INTS y2[_Nonnull 2]);108 109 110#pragma clang assume_nonnull begin111void testAssumeNonnull(112 int ints[],113#if ARRAYS_CHECKED114// 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#endif118 void *ptrs[],119#if ARRAYS_CHECKED120// 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#endif124 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_CHECKED128// 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#endif132 133void testAssumeNonnullAllOK(134 int ints[_Nonnull],135 void * _Nullable ptrs[_Nonnull],136 void * _Nullable * _Nullable nestedPtrs[_Nonnull]);137void testAssumeNonnullAllOK2(138 int ints[_Nonnull],139 void * ptrs[_Nonnull], // backwards-compatibility140 void * _Nullable * _Nullable nestedPtrs[_Nonnull]);141#pragma clang assume_nonnull end142