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