Debian Codegraph @

clang/test/Sema/non-null-warning.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -Wnonnull -Wnullability %s -verify
2
3 #if __has_feature(nullability)
4 #else
5 # error nullability feature should be defined
6 #endif
7
8
9 int * _Nullable foo(int * _Nonnull x);
10
11 int *_Nonnull ret_nonnull(void);
12
13 int *foo(int *x) {
14 return 0;
15 }
16
17 int * _Nullable foo1(int * _Nonnull x); // expected-note {{previous declaration is here}}
18
19 int *foo1(int * _Nullable x) { // expected-warning {{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
20 return 0;
21 }
22
23 int * _Nullable foo2(int * _Nonnull x);
24
25 int *foo2(int * _Nonnull x) {
26 return 0;
27 }
28
29 int * _Nullable foo3(int * _Nullable x); // expected-note {{previous declaration is here}}
30
31 int *foo3(int * _Nonnull x) { // expected-warning {{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable'}}
32 return 0;
33 }
34
35 int * ret_nonnull(void) {
36 return 0; // expected-warning {{null returned from function that requires a non-null return value}}
37 }
38
39 int foo4(int * _Nonnull x, int * y) {
40 return 0;
41 }
42
43 #define SAFE_CALL(X) if (X) foo(X)
44 int main (void) {
45 foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
46 (void)sizeof(foo(0)); // expect no diagnostic in unevaluated context.
47 SAFE_CALL(0); // expect no diagnostic for unreachable code.
48 foo4(
49 0, // expected-warning {{null passed to a callee that requires a non-null argument}}
50 0);
51 }