Use const auto& in for loops.
Change-Id: Ic437c59797ee4e7dc38291da35c72d827bc89c8d
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index dd2dece..b79c8aa 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -635,7 +635,7 @@
sigquit_flag = false;
// Print current running tests.
printf("List of current running tests:\n");
- for (auto& child_proc : child_proc_list) {
+ for (const auto& child_proc : child_proc_list) {
if (child_proc.pid != 0) {
std::string test_name = testcase_list[child_proc.testcase_id].GetTestName(child_proc.test_id);
int64_t current_time_ns = NanoTime();
@@ -646,7 +646,7 @@
} else if (sigint_flag) {
sigint_flag = false;
// Kill current running tests.
- for (auto& child_proc : child_proc_list) {
+ for (const auto& child_proc : child_proc_list) {
if (child_proc.pid != 0) {
// Send SIGKILL to ensure the child process can be killed unconditionally.
kill(child_proc.pid, SIGKILL);
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 1766762..9f887e3 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -70,7 +70,7 @@
std::vector<pthread_key_t> keys;
auto scope_guard = make_scope_guard([&keys]{
- for (auto key : keys) {
+ for (const auto& key : keys) {
EXPECT_EQ(0, pthread_key_delete(key));
}
});
@@ -108,7 +108,7 @@
}
// Don't leak keys.
- for (auto key : keys) {
+ for (const auto& key : keys) {
EXPECT_EQ(0, pthread_key_delete(key));
}
keys.clear();
@@ -1162,7 +1162,7 @@
void* maps_stack_hi = NULL;
std::vector<map_record> maps;
ASSERT_TRUE(Maps::parse_maps(&maps));
- for (auto& map : maps) {
+ for (const auto& map : maps) {
if (map.pathname == "[stack]") {
maps_stack_hi = reinterpret_cast<void*>(map.addr_end);
break;
@@ -1552,8 +1552,8 @@
}
~StrictAlignmentAllocator() {
- for (auto& p : allocated_array) {
- delete [] p;
+ for (const auto& p : allocated_array) {
+ delete[] p;
}
}
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 500377c..0a97abc 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -832,11 +832,10 @@
}
TEST(unistd, sysconf_SC_NPROCESSORS_ONLN) {
- std::string s;
- ASSERT_TRUE(android::base::ReadFileToString("/sys/devices/system/cpu/online", &s));
- std::vector<std::string> strs = android::base::Split(s, ",");
+ std::string line;
+ ASSERT_TRUE(android::base::ReadFileToString("/sys/devices/system/cpu/online", &line));
long online_cpus = 0;
- for (auto& s : strs) {
+ for (const std::string& s : android::base::Split(line, ",")) {
std::vector<std::string> numbers = android::base::Split(s, "-");
if (numbers.size() == 1u) {
online_cpus++;