Commit 0234d5d1 authored by Jim Meyering's avatar Jim Meyering Committed by Alecs King

folly: move side effects out of EXPECT_EQ args

Summary:
This avoids warnings about e.g., sizeof(k++) that result
from macro expansion.
* folly/futures/test/ExecutorTest.cpp: Move increment out
of macro argument list.
* folly/test/FBVectorTestBenchmarks.cpp.h: Likewise.
* folly/test/LazyTest.cpp: Likewise.
Otherwise, we'd get errors like this:

folly/test/LazyTest.cpp:49:118: error: expression with side effects has no effect in an unevaluated context [-Werror,-Wunevaluated-expression]
switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing::internal::IsNullLiteralHelper(++globalCount())) == 1)>::Compare("++globalCount()", "1", ++globalCount(), 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "folly/test/LazyTest.cpp", 49, gtest_ar.failure_message()) = ::testing::Message();
^

Test Plan:
Run these commands and note there are fewer errors than before:
fbconfig --clang --with-project-version=clang:dev -r folly && fbmake dbgo

Reviewed By: njormrod@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum

FB internal diff: D1848324

Tasks: 6244745

Signature: t1:1848324:1423860890:bce44c5e0895804a21957893ae6b78e76dfbc4d3
parent ccb229d5
...@@ -112,9 +112,11 @@ TEST(Executor, InlineExecutor) { ...@@ -112,9 +112,11 @@ TEST(Executor, InlineExecutor) {
size_t counter = 0; size_t counter = 0;
x.add([&]{ x.add([&]{
x.add([&]{ x.add([&]{
EXPECT_EQ(counter++, 0); EXPECT_EQ(counter, 0);
counter++;
}); });
EXPECT_EQ(counter++, 1); EXPECT_EQ(counter, 1);
counter++;
}); });
EXPECT_EQ(counter, 2); EXPECT_EQ(counter, 2);
} }
...@@ -124,9 +126,11 @@ TEST(Executor, QueuedImmediateExecutor) { ...@@ -124,9 +126,11 @@ TEST(Executor, QueuedImmediateExecutor) {
size_t counter = 0; size_t counter = 0;
x.add([&]{ x.add([&]{
x.add([&]{ x.add([&]{
EXPECT_EQ(1, counter++); EXPECT_EQ(1, counter);
counter++;
}); });
EXPECT_EQ(0, counter++); EXPECT_EQ(0, counter);
counter++;
}); });
EXPECT_EQ(2, counter); EXPECT_EQ(2, counter);
} }
......
...@@ -47,7 +47,8 @@ TESTFUN(clause_23_3_6_1_9) { ...@@ -47,7 +47,8 @@ TESTFUN(clause_23_3_6_1_9) {
EXPECT_EQ(v.size(), lst.size()); EXPECT_EQ(v.size(), lst.size());
size_t j = 0; size_t j = 0;
FOR_EACH (i, lst) { FOR_EACH (i, lst) {
EXPECT_EQ(v[j++], *i); EXPECT_EQ(v[j], *i);
j++;
} }
} }
...@@ -63,7 +64,8 @@ TESTFUN(clause_23_3_6_1_11) { ...@@ -63,7 +64,8 @@ TESTFUN(clause_23_3_6_1_11) {
EXPECT_EQ(v.size(), lst.size()); EXPECT_EQ(v.size(), lst.size());
size_t j = 0; size_t j = 0;
FOR_EACH (i, lst) { FOR_EACH (i, lst) {
EXPECT_EQ(v[j++], *i); EXPECT_EQ(v[j], *i);
j++;
} }
// aliased assign // aliased assign
...@@ -72,7 +74,8 @@ TESTFUN(clause_23_3_6_1_11) { ...@@ -72,7 +74,8 @@ TESTFUN(clause_23_3_6_1_11) {
j = 0; j = 0;
FOR_EACH (i, lst) { FOR_EACH (i, lst) {
if (j == v.size()) break; if (j == v.size()) break;
EXPECT_EQ(v[j++], *i); EXPECT_EQ(v[j], *i);
j++;
} }
} }
......
...@@ -27,7 +27,8 @@ TEST(Lazy, Simple) { ...@@ -27,7 +27,8 @@ TEST(Lazy, Simple) {
int computeCount = 0; int computeCount = 0;
auto const val = folly::lazy([&]() -> int { auto const val = folly::lazy([&]() -> int {
EXPECT_EQ(++computeCount, 1); ++computeCount;
EXPECT_EQ(computeCount, 1);
return 12; return 12;
}); });
EXPECT_EQ(computeCount, 0); EXPECT_EQ(computeCount, 0);
...@@ -46,7 +47,8 @@ TEST(Lazy, Simple) { ...@@ -46,7 +47,8 @@ TEST(Lazy, Simple) {
auto globalCount = folly::lazy([]{ return 0; }); auto globalCount = folly::lazy([]{ return 0; });
auto const foo = folly::lazy([]() -> std::string { auto const foo = folly::lazy([]() -> std::string {
EXPECT_EQ(++globalCount(), 1); ++globalCount();
EXPECT_EQ(globalCount(), 1);
return std::string("YEP"); return std::string("YEP");
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment