diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2016-07-20 01:48:11 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2016-07-20 01:48:11 +0000 |
commit | 73118fd10e593d56cce5dd47cdba98e769a120c5 (patch) | |
tree | 05b0e97179f1c9a3b7932415cd645452995e5cdc /clang/test/SemaCXX/nullability.cpp | |
parent | 6d9ca182fe70de60ed76e635fc7311fa8669a3cd (diff) | |
download | bcm5719-llvm-73118fd10e593d56cce5dd47cdba98e769a120c5.tar.gz bcm5719-llvm-73118fd10e593d56cce5dd47cdba98e769a120c5.zip |
[Sema] Compute the nullability of a conditional expression based on the
nullabilities of its operands.
This patch defines a function to compute the nullability of conditional
expressions, which enables Sema to precisely detect implicit conversions
of nullable conditional expressions to nonnull pointers.
rdar://problem/25166556
Differential Revision: https://reviews.llvm.org/D22392
llvm-svn: 276076
Diffstat (limited to 'clang/test/SemaCXX/nullability.cpp')
-rw-r--r-- | clang/test/SemaCXX/nullability.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/nullability.cpp b/clang/test/SemaCXX/nullability.cpp index c73c01a0a86..2af25730b66 100644 --- a/clang/test/SemaCXX/nullability.cpp +++ b/clang/test/SemaCXX/nullability.cpp @@ -97,3 +97,23 @@ 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}} +} |