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.
49 lines
1000 B
49 lines
1000 B
7 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
7 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
7 years ago
|
*/
|
||
|
#include <vector>
|
||
|
|
||
7 years ago
|
void foreach_access1_ok(std::vector<int>& vec) {
|
||
7 years ago
|
if (vec.empty()) {
|
||
|
// do nothing
|
||
|
}
|
||
|
for (const auto& elem : vec) {
|
||
|
auto r = elem;
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
void foreach_access2_ok(std::vector<int>& vec) {
|
||
|
int s = vec.size();
|
||
|
for (const auto& elem : vec) {
|
||
|
auto r = elem;
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
void iterator_for_access_ok(std::vector<int>& vec) {
|
||
|
if (vec.empty()) {
|
||
|
// do nothing
|
||
|
}
|
||
|
for (auto it = vec.begin(); it != vec.end(); ++it) {
|
||
|
auto r = *it;
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
void FP_empty_vector_loop_ok() {
|
||
7 years ago
|
std::vector<int> vec;
|
||
|
int* ptr = nullptr;
|
||
|
for (const auto& elem : vec) {
|
||
|
*ptr = elem; // this is unreachable
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void non_empty_vector_loop_bad(std::vector<int>& vec) {
|
||
|
std::vector<int> x;
|
||
|
int* ptr = nullptr;
|
||
|
for (const auto& elem : vec) {
|
||
|
*ptr = elem; // this is reachable
|
||
|
}
|
||
|
}
|