You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
/*
|
|
* Copyright (c) 2017 - present Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
class T {
|
|
private:
|
|
int* unnanotated_field;
|
|
int* _Nullable nullable_field;
|
|
int* _Nonnull nonnull_field;
|
|
|
|
public:
|
|
void assign_nullable_field_to_null_okay() { nullable_field = nullptr; }
|
|
|
|
public:
|
|
void assign_unnanotated_field_to_null_bad() { unnanotated_field = nullptr; }
|
|
|
|
public:
|
|
void assign_nonnull_field_to_null_bad() { nonnull_field = nullptr; }
|
|
|
|
public:
|
|
void test_nullable_field_for_null_okay() {
|
|
if (nullable_field == nullptr) {
|
|
}
|
|
}
|
|
|
|
public:
|
|
void test_unnanotated_field_for_null_bad() {
|
|
if (unnanotated_field == nullptr) {
|
|
}
|
|
}
|
|
|
|
public:
|
|
void test_nonnull_field_for_null_bad() {
|
|
if (nonnull_field == nullptr) {
|
|
}
|
|
}
|
|
|
|
public:
|
|
void dereference_unnanotated_field_okay() { *unnanotated_field = 42; }
|
|
|
|
public:
|
|
void dereference_nonnull_field_okay() { *nonnull_field = 42; }
|
|
|
|
public:
|
|
void dereference_nullable_field_bad() { *nullable_field = 42; }
|
|
|
|
public:
|
|
void dereference_unnanotated_field_after_test_for_null_bad() {
|
|
if (unnanotated_field == nullptr) {
|
|
*unnanotated_field = 42;
|
|
}
|
|
}
|
|
|
|
public:
|
|
void FP_dereference_nonnull_field_after_test_for_null_okay() {
|
|
if (nonnull_field == nullptr) {
|
|
*nonnull_field = 42;
|
|
}
|
|
}
|
|
};
|