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