diff options
Diffstat (limited to 'test/SemaCXX/nullability.cpp')
-rw-r--r-- | test/SemaCXX/nullability.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/SemaCXX/nullability.cpp b/test/SemaCXX/nullability.cpp index c73c01a0a862c..160741b1409c6 100644 --- a/test/SemaCXX/nullability.cpp +++ b/test/SemaCXX/nullability.cpp @@ -97,3 +97,36 @@ void AssignAndInitNonNullFromFn() { TakeNonnull(ReturnNullable()); //expected-warning{{implicit conversion from nullable pointer 'void * _Nullable' to non-nullable pointer type 'void * _Nonnull}} } + +void ConditionalExpr(bool c) { + struct Base {}; + struct Derived : Base {}; + + Base * _Nonnull p; + Base * _Nonnull nonnullB; + Base * _Nullable nullableB; + Derived * _Nonnull nonnullD; + Derived * _Nullable nullableD; + + p = c ? nonnullB : nonnullD; + p = c ? nonnullB : nullableD; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} + p = c ? nullableB : nonnullD; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} + p = c ? nullableB : nullableD; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} + p = c ? nonnullD : nonnullB; + p = c ? nonnullD : nullableB; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} + p = c ? nullableD : nonnullB; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} + p = c ? nullableD : nullableB; // expected-warning{{implicit conversion from nullable pointer 'Base * _Nullable' to non-nullable pointer type 'Base * _Nonnull}} +} + +void arraysInLambdas() { + typedef int INTS[4]; + auto simple = [](int [_Nonnull 2]) {}; + simple(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto nested = [](void *_Nullable [_Nonnull 2]) {}; + nested(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto nestedBad = [](int [2][_Nonnull 2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [2]'}} + + auto withTypedef = [](INTS _Nonnull) {}; + withTypedef(nullptr); // expected-warning {{null passed to a callee that requires a non-null argument}} + auto withTypedefBad = [](INTS _Nonnull[2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}} +} |