From 94b8816bbdca38914030842554cc955caee59063 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Mon, 18 Sep 2017 22:54:48 -0700 Subject: [PATCH] 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 --- folly/RWSpinLock.h | 2 +- folly/concurrency/detail/ConcurrentHashMap-detail.h | 1 - folly/concurrency/test/ConcurrentHashMapTest.cpp | 2 -- folly/executors/IOThreadPoolExecutor.cpp | 4 ++-- folly/experimental/bser/test/BserTest.cpp | 1 + .../test/ExceptionTracerBenchmark.cpp | 2 +- folly/experimental/logging/LoggerDB.cpp | 2 +- folly/experimental/test/FutureDAGTest.cpp | 1 + folly/futures/test/TestExecutor.cpp | 1 + folly/gen/test/BaseBenchmark.cpp | 2 -- folly/gen/test/ParallelBenchmark.cpp | 12 ------------ folly/gen/test/StringTest.cpp | 2 +- folly/test/FBVectorTestBenchmarks.cpp.h | 1 - folly/test/IPAddressBenchmark.cpp | 10 +++++++--- folly/test/OptionalCoroutinesTest.cpp | 1 + folly/test/RangeTest.cpp | 1 - folly/test/ScopeGuardTest.cpp | 13 +++++++++++++ folly/test/UncaughtExceptionsTest.cpp | 1 + folly/test/function_benchmark/main.cpp | 7 +++++++ folly/test/stl_tests/StlVectorTest.cpp | 2 ++ 20 files changed, 40 insertions(+), 28 deletions(-) diff --git a/folly/RWSpinLock.h b/folly/RWSpinLock.h index 6a5436dc..3cce0d90 100644 --- a/folly/RWSpinLock.h +++ b/folly/RWSpinLock.h @@ -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; diff --git a/folly/concurrency/detail/ConcurrentHashMap-detail.h b/folly/concurrency/detail/ConcurrentHashMap-detail.h index 7b9da9c0..ebbb44fc 100644 --- a/folly/concurrency/detail/ConcurrentHashMap-detail.h +++ b/folly/concurrency/detail/ConcurrentHashMap-detail.h @@ -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); diff --git a/folly/concurrency/test/ConcurrentHashMapTest.cpp b/folly/concurrency/test/ConcurrentHashMapTest.cpp index 4a1d23d1..cf283c41 100644 --- a/folly/concurrency/test/ConcurrentHashMapTest.cpp +++ b/folly/concurrency/test/ConcurrentHashMapTest.cpp @@ -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); diff --git a/folly/executors/IOThreadPoolExecutor.cpp b/folly/executors/IOThreadPoolExecutor.cpp index 1cf9bc5e..7e16e80a 100644 --- a/folly/executors/IOThreadPoolExecutor.cpp +++ b/folly/executors/IOThreadPoolExecutor.cpp @@ -47,9 +47,9 @@ class MemoryIdlerTimeout : public AsyncTimeout, public EventBase::LoopCallback { idleTimeout = MemoryIdler::getVariationTimeout(idleTimeout); - scheduleTimeout( + scheduleTimeout(static_cast( std::chrono::duration_cast(idleTimeout) - .count()); + .count())); } // reschedule this callback for the next event loop. diff --git a/folly/experimental/bser/test/BserTest.cpp b/folly/experimental/bser/test/BserTest.cpp index 9c053558..fd1cfd0f 100644 --- a/folly/experimental/bser/test/BserTest.cpp +++ b/folly/experimental/bser/test/BserTest.cpp @@ -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); diff --git a/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp b/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp index 35f536fc..af39fc05 100644 --- a/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp +++ b/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp @@ -45,7 +45,7 @@ void loop(int iters) { BENCHMARK(ExceptionTracer, iters) { std::vector threads; constexpr size_t kNumThreads = 10; - threads.resize(10); + threads.resize(kNumThreads); for (auto& t : threads) { t = std::thread([iters]() { loop(iters); }); } diff --git a/folly/experimental/logging/LoggerDB.cpp b/folly/experimental/logging/LoggerDB.cpp index 79a1c068..516485aa 100644 --- a/folly/experimental/logging/LoggerDB.cpp +++ b/folly/experimental/logging/LoggerDB.cpp @@ -123,7 +123,7 @@ std::vector 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; diff --git a/folly/experimental/test/FutureDAGTest.cpp b/folly/experimental/test/FutureDAGTest.cpp index 98329c90..01d4aa8c 100644 --- a/folly/experimental/test/FutureDAGTest.cpp +++ b/folly/experimental/test/FutureDAGTest.cpp @@ -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(); diff --git a/folly/futures/test/TestExecutor.cpp b/folly/futures/test/TestExecutor.cpp index 7f024127..f7170774 100644 --- a/folly/futures/test/TestExecutor.cpp +++ b/folly/futures/test/TestExecutor.cpp @@ -43,6 +43,7 @@ TestExecutor::TestExecutor(size_t numThreads) { TestExecutor::~TestExecutor() { for (auto& worker : workers_) { + (void)worker; addImpl({}); } diff --git a/folly/gen/test/BaseBenchmark.cpp b/folly/gen/test/BaseBenchmark.cpp index a059898f..f11fef0f 100644 --- a/folly/gen/test/BaseBenchmark.cpp +++ b/folly/gen/test/BaseBenchmark.cpp @@ -46,8 +46,6 @@ static vector strings = | as(); 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(); diff --git a/folly/gen/test/ParallelBenchmark.cpp b/folly/gen/test/ParallelBenchmark.cpp index 9bced1ee..7d41dfcd 100644 --- a/folly/gen/test/ParallelBenchmark.cpp +++ b/folly/gen/test/ParallelBenchmark.cpp @@ -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 lock(block); - return sleepyWork(i) + r; - } -}; - auto start = 1 << 20; auto v = seq(start) | take(1 << 20) | as(); auto small = from(v) | take(1 << 12); diff --git a/folly/gen/test/StringTest.cpp b/folly/gen/test/StringTest.cpp index 4d8288bd..47d76d2b 100644 --- a/folly/gen/test/StringTest.cpp +++ b/folly/gen/test/StringTest.cpp @@ -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 diff --git a/folly/test/FBVectorTestBenchmarks.cpp.h b/folly/test/FBVectorTestBenchmarks.cpp.h index 25c7e39a..e5181e4b 100644 --- a/folly/test/FBVectorTestBenchmarks.cpp.h +++ b/folly/test/FBVectorTestBenchmarks.cpp.h @@ -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()); } diff --git a/folly/test/IPAddressBenchmark.cpp b/folly/test/IPAddressBenchmark.cpp index 4e1cf14a..fc9ca727 100644 --- a/folly/test/IPAddressBenchmark.cpp +++ b/folly/test/IPAddressBenchmark.cpp @@ -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()); } } diff --git a/folly/test/OptionalCoroutinesTest.cpp b/folly/test/OptionalCoroutinesTest.cpp index 9d77718a..fd0ba0ec 100644 --- a/folly/test/OptionalCoroutinesTest.cpp +++ b/folly/test/OptionalCoroutinesTest.cpp @@ -74,6 +74,7 @@ TEST(Optional, CoroutineException) { ADD_FAILURE(); co_return x; }(); + (void)r2; ADD_FAILURE(); } catch (/* nolint */ int i) { EXPECT_EQ(42, i); diff --git a/folly/test/RangeTest.cpp b/folly/test/RangeTest.cpp index 3aa31786..e80bb6ea 100644 --- a/folly/test/RangeTest.cpp +++ b/folly/test/RangeTest.cpp @@ -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(); diff --git a/folly/test/ScopeGuardTest.cpp b/folly/test/ScopeGuardTest.cpp index 853c7b29..0b635c02 100644 --- a/folly/test/ScopeGuardTest.cpp +++ b/folly/test/ScopeGuardTest.cpp @@ -48,6 +48,7 @@ TEST(ScopeGuard, DifferentWaysToBind) { // There is implicit conversion from func pointer // double (*)() to function. ScopeGuard g = makeGuard(returnsDouble); + (void)g; } vector v; @@ -57,36 +58,42 @@ TEST(ScopeGuard, DifferentWaysToBind) { { // binding to member function. ScopeGuard g = makeGuard(std::bind(&vector::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) { diff --git a/folly/test/UncaughtExceptionsTest.cpp b/folly/test/UncaughtExceptionsTest.cpp index 781374bc..e5e64e3e 100644 --- a/folly/test/UncaughtExceptionsTest.cpp +++ b/folly/test/UncaughtExceptionsTest.cpp @@ -109,6 +109,7 @@ struct ThrowInDestructor { ~ThrowInDestructor() { try { InnerThrowInDestructor stackObjectThrowingOnUnwind; + (void)stackObjectThrowingOnUnwind; Validator validator( N - I + 1, "validating in " + folly::to(I)); LOG(INFO) << "throwing in ~ThrowInDestructor " << I; diff --git a/folly/test/function_benchmark/main.cpp b/folly/test/function_benchmark/main.cpp index 20d5b7dd..18e8b929 100644 --- a/folly/test/function_benchmark/main.cpp +++ b/folly/test/function_benchmark/main.cpp @@ -159,6 +159,7 @@ BENCHMARK(scope_guard_std_function, iters) { std::function 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(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(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. diff --git a/folly/test/stl_tests/StlVectorTest.cpp b/folly/test/stl_tests/StlVectorTest.cpp index 42920e13..7e0139d6 100644 --- a/folly/test/stl_tests/StlVectorTest.cpp +++ b/folly/test/stl_tests/StlVectorTest.cpp @@ -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 ; \ + (void)f; \ return true; \ } \ template bool test_I_ ## name ## 3 () { \ -- 2.34.1