52 lines · c
1// RUN: %clang_cc1 -fsyntax-only -Wnonnull -Wnullability %s -verify2 3#if __has_feature(nullability)4#else5# error nullability feature should be defined6#endif7 8 9int * _Nullable foo(int * _Nonnull x);10 11int *_Nonnull ret_nonnull(void);12 13int *foo(int *x) {14 return 0;15}16 17int * _Nullable foo1(int * _Nonnull x); // expected-note {{previous declaration is here}}18 19int *foo1(int * _Nullable x) { // expected-warning {{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}20 return 0;21}22 23int * _Nullable foo2(int * _Nonnull x);24 25int *foo2(int * _Nonnull x) {26 return 0;27}28 29int * _Nullable foo3(int * _Nullable x); // expected-note {{previous declaration is here}}30 31int *foo3(int * _Nonnull x) { // expected-warning {{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable'}}32 return 0;33}34 35int * ret_nonnull(void) {36 return 0; // expected-warning {{null returned from function that requires a non-null return value}}37}38 39int foo4(int * _Nonnull x, int * y) {40 return 0;41}42 43#define SAFE_CALL(X) if (X) foo(X)44int 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}52