Commit 94b8816b authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Enable -Wunused-variables

Summary:
Only for clang for the moment, as more work is needed for GCC.
MSVC builds have always had unused variable warnings enabled, I just hadn't gotten around to cleaning up all of the tests for it to be able to enable it.

Reviewed By: yfeldblum

Differential Revision: D5827840

fbshipit-source-id: ab503b5791fcc58d685b8327179b810880c5dea7
parent f3bce424
......@@ -678,7 +678,7 @@ class RWTicketSpinLockT {
}
void unlock_shared() {
QuarterInt val = __sync_fetch_and_add(&ticket.write, 1);
__sync_fetch_and_add(&ticket.write, 1);
}
class WriteHolder;
......
......@@ -513,7 +513,6 @@ class FOLLY_ALIGNED(64) ConcurrentHashMapSegment {
auto head = &buckets->buckets_[idx];
node = head->load(std::memory_order_relaxed);
Node* prev = nullptr;
auto headnode = node;
while (node) {
if (KeyEqual()(key, node->getItem().first)) {
auto next = node->next_.load(std::memory_order_relaxed);
......
......@@ -294,7 +294,6 @@ TEST(ConcurrentHashMap, EraseStressTest) {
int offset = (iters * t / num_threads);
for (uint i = 0; i < iters / num_threads; i++) {
unsigned long k = folly::hash::jenkins_rev_mix32((i + offset));
unsigned long val;
auto res = m.insert(k, k).second;
if (res) {
res = m.erase(k);
......@@ -357,7 +356,6 @@ TEST(ConcurrentHashMap, IterateStressTest) {
int offset = (iters * t / num_threads);
for (uint i = 0; i < iters / num_threads; i++) {
unsigned long k = folly::hash::jenkins_rev_mix32((i + offset));
unsigned long val;
auto res = m.insert(k, k).second;
if (res) {
res = m.erase(k);
......
......@@ -47,9 +47,9 @@ class MemoryIdlerTimeout : public AsyncTimeout, public EventBase::LoopCallback {
idleTimeout = MemoryIdler::getVariationTimeout(idleTimeout);
scheduleTimeout(
scheduleTimeout(static_cast<uint32_t>(
std::chrono::duration_cast<std::chrono::milliseconds>(idleTimeout)
.count());
.count()));
}
// reschedule this callback for the next event loop.
......
......@@ -108,6 +108,7 @@ TEST(Bser, PduLength) {
// complete length available
auto buf = folly::IOBuf::wrapBuffer(template_blob, 3);
auto len = folly::bser::decodePduLength(&*buf);
(void)len;
LOG(ERROR) << "managed to return a length, but only had 3 bytes";
}(),
std::out_of_range);
......
......@@ -45,7 +45,7 @@ void loop(int iters) {
BENCHMARK(ExceptionTracer, iters) {
std::vector<std::thread> threads;
constexpr size_t kNumThreads = 10;
threads.resize(10);
threads.resize(kNumThreads);
for (auto& t : threads) {
t = std::thread([iters]() { loop(iters); });
}
......
......@@ -123,7 +123,7 @@ std::vector<std::string> LoggerDB::processConfigString(
LogLevel level;
try {
level = stringToLogLevel(level_str);
} catch (const std::exception& ex) {
} catch (const std::exception&) {
errors.emplace_back(folly::sformat(
"invalid log level \"{}\" for category \"{}\"", level_str, category));
continue;
......
......@@ -107,6 +107,7 @@ TEST_F(FutureDAGTest, SingleNode) {
TEST_F(FutureDAGTest, RemoveSingleNode) {
auto h1 = add();
auto h2 = add();
(void)h1;
remove(h2);
ASSERT_NO_THROW(dag->go().get());
checkOrder();
......
......@@ -43,6 +43,7 @@ TestExecutor::TestExecutor(size_t numThreads) {
TestExecutor::~TestExecutor() {
for (auto& worker : workers_) {
(void)worker;
addImpl({});
}
......
......@@ -46,8 +46,6 @@ static vector<fbstring> strings =
| as<vector>();
auto square = [](int x) { return x * x; };
auto add = [](int a, int b) { return a + b; };
auto multiply = [](int a, int b) { return a * b; };
BENCHMARK(Sum_Basic_NoGen, iters) {
int limit = testSize.load();
......
......@@ -37,9 +37,6 @@ using std::vector;
constexpr int kFib = 28; // unit of work
size_t fib(int n) { return n <= 1 ? 1 : fib(n - 1) + fib(n - 2); }
static auto add = [](int a, int b) { return a + b; };
static auto mod7 = [](int i) { return i % 7; };
static auto isPrimeSlow = [](int n) {
if (n < 2) {
return false;
......@@ -86,15 +83,6 @@ static auto sleepAndWork = [](int i) {
return factorsSlow(i) + sleepyWork(i);
};
std::mutex block;
static auto workAndBlock = [](int i) {
int r = factorsSlow(i);
{
std::lock_guard<std::mutex> lock(block);
return sleepyWork(i) + r;
}
};
auto start = 1 << 20;
auto v = seq(start) | take(1 << 20) | as<vector>();
auto small = from(v) | take(1 << 12);
......
......@@ -40,7 +40,7 @@ TEST(StringGen, EmptySplit) {
{
auto input = "";
auto expected = vec{};
EXPECT_EQ(expected, split("", ',') | collect);
EXPECT_EQ(expected, split(input, ',') | collect);
}
// The last delimiter is eaten, just like std::getline
......
......@@ -121,7 +121,6 @@ TESTFUN(clause_23_3_6_2_9) {
FOR_EACH (i, v) {
EXPECT_EQ(*i, VECTOR::value_type());
}
auto const n2 = random(0U, 10000U);
FOR_EACH (i, v) {
EXPECT_EQ(*i, VECTOR::value_type());
}
......
......@@ -32,6 +32,7 @@ BENCHMARK(ipv4_to_string_inet_ntop, iters) {
while (iters--) {
const char* val =
inet_ntop(AF_INET, &ip, outputString, sizeof(outputString));
folly::doNotOptimizeAway(val);
}
}
......@@ -39,6 +40,8 @@ BENCHMARK_RELATIVE(ipv4_to_fully_qualified, iters) {
IPAddressV4 ip("127.0.0.1");
while (iters--) {
string outputString = ip.toFullyQualified();
folly::doNotOptimizeAway(outputString);
folly::doNotOptimizeAway(outputString.data());
}
}
......@@ -72,19 +75,20 @@ BENCHMARK(ipv6_to_string_inet_ntop, iters) {
IPAddressV6 ipv6Addr("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
in6_addr ip = ipv6Addr.toAddr();
char outputString[INET6_ADDRSTRLEN] = {0};
bool checkResult = (iters == 1);
while (iters--) {
const char* val =
inet_ntop(AF_INET6, &ip, outputString, sizeof(outputString));
folly::doNotOptimizeAway(val);
}
}
BENCHMARK_RELATIVE(ipv6_to_fully_qualified, iters) {
IPAddressV6 ip("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
string outputString;
while (iters--) {
outputString = ip.toFullyQualified();
string outputString = ip.toFullyQualified();
folly::doNotOptimizeAway(outputString);
folly::doNotOptimizeAway(outputString.data());
}
}
......
......@@ -74,6 +74,7 @@ TEST(Optional, CoroutineException) {
ADD_FAILURE();
co_return x;
}();
(void)r2;
ADD_FAILURE();
} catch (/* nolint */ int i) {
EXPECT_EQ(42, i);
......
......@@ -1003,7 +1003,6 @@ const size_t kPageSize = 4096;
// This function will also initialize buf, which caller must free().
void createProtectedBuf(StringPiece& contents, char** buf) {
ASSERT_LE(contents.size(), kPageSize);
const size_t kSuccess = 0;
char* pageAlignedBuf = (char*)aligned_malloc(2 * kPageSize, kPageSize);
if (pageAlignedBuf == nullptr) {
FAIL();
......
......@@ -48,6 +48,7 @@ TEST(ScopeGuard, DifferentWaysToBind) {
// There is implicit conversion from func pointer
// double (*)() to function<void()>.
ScopeGuard g = makeGuard(returnsDouble);
(void)g;
}
vector<int> v;
......@@ -57,36 +58,42 @@ TEST(ScopeGuard, DifferentWaysToBind) {
{
// binding to member function.
ScopeGuard g = makeGuard(std::bind(&vector<int>::pop_back, &v));
(void)g;
}
EXPECT_EQ(0, v.size());
{
// bind member function with args. v is passed-by-value!
ScopeGuard g = makeGuard(std::bind(push_back, v, 2));
(void)g;
}
EXPECT_EQ(0, v.size()); // push_back happened on a copy of v... fail!
// pass in an argument by pointer so to avoid copy.
{
ScopeGuard g = makeGuard(std::bind(push_back, &v, 4));
(void)g;
}
EXPECT_EQ(1, v.size());
{
// pass in an argument by reference so to avoid copy.
ScopeGuard g = makeGuard(std::bind(push_back, std::ref(v), 4));
(void)g;
}
EXPECT_EQ(2, v.size());
// lambda with a reference to v
{
ScopeGuard g = makeGuard([&] { v.push_back(5); });
(void)g;
}
EXPECT_EQ(3, v.size());
// lambda with a copy of v
{
ScopeGuard g = makeGuard([v] () mutable { v.push_back(6); });
(void)g;
}
EXPECT_EQ(3, v.size());
......@@ -95,6 +102,7 @@ TEST(ScopeGuard, DifferentWaysToBind) {
{
MyFunctor f(&n);
ScopeGuard g = makeGuard(f);
(void)g;
}
EXPECT_EQ(1, n);
......@@ -102,6 +110,7 @@ TEST(ScopeGuard, DifferentWaysToBind) {
n = 0;
{
ScopeGuard g = makeGuard(MyFunctor(&n));
(void)g;
}
EXPECT_EQ(1, n);
......@@ -109,6 +118,7 @@ TEST(ScopeGuard, DifferentWaysToBind) {
n = 2;
{
auto g = makeGuard(MyFunctor(&n));
(void)g;
}
EXPECT_EQ(3, n);
......@@ -116,6 +126,7 @@ TEST(ScopeGuard, DifferentWaysToBind) {
n = 10;
{
const auto& g = makeGuard(MyFunctor(&n));
(void)g;
}
EXPECT_EQ(11, n);
}
......@@ -125,6 +136,7 @@ TEST(ScopeGuard, GuardException) {
ScopeGuard g = makeGuard([&] {
throw std::runtime_error("destructors should never throw!");
});
(void)g;
},
"destructors should never throw!"
);
......@@ -196,6 +208,7 @@ void testFinally(ErrorBehavior error) {
try {
ScopeGuard guard = makeGuard([&] { cleanupOccurred = true; });
(void)guard;
try {
if (error == ErrorBehavior::HANDLED_ERROR) {
......
......@@ -109,6 +109,7 @@ struct ThrowInDestructor {
~ThrowInDestructor() {
try {
InnerThrowInDestructor stackObjectThrowingOnUnwind;
(void)stackObjectThrowingOnUnwind;
Validator validator(
N - I + 1, "validating in " + folly::to<std::string>(I));
LOG(INFO) << "throwing in ~ThrowInDestructor " << I;
......
......@@ -159,6 +159,7 @@ BENCHMARK(scope_guard_std_function, iters) {
std::function<void()> fn(doNothing);
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(fn);
(void)g;
}
}
......@@ -167,6 +168,7 @@ BENCHMARK(scope_guard_std_function, iters) {
BENCHMARK(scope_guard_std_function_rvalue, iters) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(std::function<void()>(doNothing));
(void)g;
}
}
......@@ -175,6 +177,7 @@ BENCHMARK(scope_guard_std_function_rvalue, iters) {
BENCHMARK(scope_guard_Function_rvalue, iters) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(folly::Function<void()>(doNothing));
(void)g;
}
}
......@@ -182,6 +185,7 @@ BENCHMARK(scope_guard_Function_rvalue, iters) {
BENCHMARK(scope_guard_fn_ptr, iters) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(doNothing);
(void)g;
}
}
......@@ -189,6 +193,7 @@ BENCHMARK(scope_guard_fn_ptr, iters) {
BENCHMARK(scope_guard_lambda_noop, iters) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] {});
(void)g;
}
}
......@@ -196,6 +201,7 @@ BENCHMARK(scope_guard_lambda_noop, iters) {
BENCHMARK(scope_guard_lambda_function, iters) {
for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] { doNothing(); });
(void)g;
}
}
......@@ -212,6 +218,7 @@ BENCHMARK(scope_guard_lambda_local_var, iters) {
++count;
}
});
(void)g;
}
// Check that the value of count is what we expect.
......
......@@ -194,6 +194,7 @@ THOUGHTS:
// but it also means we have some parameters that may not be used.
FOLLY_PUSH_WARNING
FOLLY_GCC_DISABLE_WARNING("-Wunused-parameter")
FOLLY_GCC_DISABLE_WARNING("-Wunused-variable")
using namespace std;
using namespace folly;
......@@ -928,6 +929,7 @@ uint64_t ReadTSC() {
return true; \
auto f = test_ ## name <Vector, \
typename Vector::value_type, typename Vector::allocator_type>; \
(void)f; \
return true; \
} \
template <class Vector> bool test_I_ ## name ## 3 () { \
......
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