Enable -Wunused-variables
authorChristopher Dykes <cdykes@fb.com>
Tue, 19 Sep 2017 05:54:48 +0000 (22:54 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 19 Sep 2017 06:10:22 +0000 (23:10 -0700)
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

20 files changed:
folly/RWSpinLock.h
folly/concurrency/detail/ConcurrentHashMap-detail.h
folly/concurrency/test/ConcurrentHashMapTest.cpp
folly/executors/IOThreadPoolExecutor.cpp
folly/experimental/bser/test/BserTest.cpp
folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp
folly/experimental/logging/LoggerDB.cpp
folly/experimental/test/FutureDAGTest.cpp
folly/futures/test/TestExecutor.cpp
folly/gen/test/BaseBenchmark.cpp
folly/gen/test/ParallelBenchmark.cpp
folly/gen/test/StringTest.cpp
folly/test/FBVectorTestBenchmarks.cpp.h
folly/test/IPAddressBenchmark.cpp
folly/test/OptionalCoroutinesTest.cpp
folly/test/RangeTest.cpp
folly/test/ScopeGuardTest.cpp
folly/test/UncaughtExceptionsTest.cpp
folly/test/function_benchmark/main.cpp
folly/test/stl_tests/StlVectorTest.cpp

index 6a5436dc69dfd639d837af1e4b936ba6eb3739af..3cce0d90603ef02b1dafec7ac5581279a1d020d4 100644 (file)
@@ -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;
index 7b9da9c0204e347f595c2b4ccdd4e496fb162375..ebbb44fc400181ceb3ee937ead97b71d2f303b7a 100644 (file)
@@ -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);
index 4a1d23d16349196736ed570280c3c5a5b1c125db..cf283c4112bc1e46ee08bc79eb0c671a84e0c9a1 100644 (file)
@@ -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);
index 1cf9bc5e336d24fbc530df8b68d2eb9366dd1ec8..7e16e80aec991c9f24a0ab48905e505ef5311c8f 100644 (file)
@@ -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.
index 9c05355855635ceb41be4bacea232c1472a0da2b..fd1cfd0fbb543d369753bd5fe4b93fefbf29ebfc 100644 (file)
@@ -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);
index 35f536fc33994a3f71d42da45c3e06deec0dacb6..af39fc05ec69d1b83351b556c15de415d7656c67 100644 (file)
@@ -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); });
   }
index 79a1c068d657e5e422fd68df573c22861cb25e23..516485aa8bc01822c23668556e1dbcac3a47bb49 100644 (file)
@@ -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;
index 98329c9035e0cb7ca07afb813e2813690fe79b9d..01d4aa8cc9c0de3201b7a08ac2d583e1792a1b25 100644 (file)
@@ -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();
index 7f024127bf6f504c9fbdbcacb386a0fdb2161dd0..f7170774820be9fe20f2a073a4fba4fe4cc7ba96 100644 (file)
@@ -43,6 +43,7 @@ TestExecutor::TestExecutor(size_t numThreads) {
 
 TestExecutor::~TestExecutor() {
   for (auto& worker : workers_) {
+    (void)worker;
     addImpl({});
   }
 
index a059898f1156a882c7d54a20758dcf439267d098..f11fef0f07bff442fdebf734765f7d75657ffbda 100644 (file)
@@ -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();
index 9bced1ee34b50fef40b27cb936d050ff34094acb..7d41dfcdb5a4d65d384e7f9bcd025448bd710b95 100644 (file)
@@ -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);
index 4d8288bdc67d6c4139cc55ad285d2347cd8b5e2e..47d76d2bf33b30f211ead56ba1350524cadc3dfd 100644 (file)
@@ -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
index 25c7e39a30ac618642117edd020c001a257db267..e5181e4bedece35b6d58d5a9676364dc2f3f11ec 100644 (file)
@@ -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());
   }
index 4e1cf14ac91a7d2d23560aa3bf6fcf194bdd709b..fc9ca7272089ecba68bf8a9244dcc598a5afe74a 100644 (file)
@@ -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());
   }
 }
 
index 9d77718ac41cca8677e62fa937e15e09fac01c1e..fd0ba0ecc5dccf8ff5e2c3390070e3b885f6b79b 100644 (file)
@@ -74,6 +74,7 @@ TEST(Optional, CoroutineException) {
       ADD_FAILURE();
       co_return x;
     }();
+    (void)r2;
     ADD_FAILURE();
   } catch (/* nolint */ int i) {
     EXPECT_EQ(42, i);
index 3aa31786cf4bb5145ff1227aad1bb0f649a58b78..e80bb6eae70beddcbc0cc704f022d610e084d97f 100644 (file)
@@ -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();
index 853c7b29aaa454ef62dffa209f88f3399271be9c..0b635c02e1327daf5244c8142cd0a07326d2be59 100644 (file)
@@ -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) {
index 781374bc50c4d06523ff31d5b505fa2c8bca47c2..e5e64e3e609fc5a575134d89c9ed8aa713321cf5 100644 (file)
@@ -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;
index 20d5b7ddff4a0f9fa89b6b4cdca246f17a3e1848..18e8b92962ae916c24e5d8f724cd52a53d85534e 100644 (file)
@@ -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.
index 42920e13e99904935f648ea367f6802e3b9bfa87..7e0139d63a84b13e92559ddb572ad295e50481d9 100644 (file)
@@ -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 () {                 \