fix compiler warnings from gcc-4.9 + -Wunused-variable
authorNathan Bronson <ngbronson@fb.com>
Fri, 2 Oct 2015 01:39:47 +0000 (18:39 -0700)
committerfacebook-github-bot-5 <folly-bot@fb.com>
Fri, 2 Oct 2015 15:56:57 +0000 (08:56 -0700)
Summary: This diff fixes the compiler warnings emitted by gcc-4.9's
stricter -Wsigned-comparison check, as well as those revealed by
-Wunused-variable.

Reviewed By: @meyering, @yfeldblum

Differential Revision: D2494514

32 files changed:
folly/Benchmark.cpp
folly/experimental/Bits.h
folly/experimental/EventCount.h
folly/experimental/fibers/AddTasks-inl.h
folly/experimental/fibers/Fiber.cpp
folly/experimental/fibers/WhenN-inl.h
folly/experimental/fibers/test/FibersTest.cpp
folly/futures/test/CollectTest.cpp
folly/io/async/AsyncPipe.cpp
folly/io/async/AsyncSSLSocket.cpp
folly/io/async/test/AsyncSSLSocketTest.cpp
folly/io/async/test/HHWheelTimerTest.cpp
folly/io/test/IOBufCursorTest.cpp
folly/io/test/IOBufQueueTest.cpp
folly/io/test/IOBufTest.cpp
folly/test/AtomicHashMapTest.cpp
folly/test/ConvTest.cpp
folly/test/DeterministicSchedule.cpp
folly/test/DynamicTest.cpp
folly/test/FBStringTest.cpp
folly/test/FileTest.cpp
folly/test/ForeachTest.cpp
folly/test/FormatTest.cpp
folly/test/IPAddressTest.cpp
folly/test/OptionalTest.cpp
folly/test/SharedMutexTest.cpp
folly/test/SingletonTest.cpp
folly/test/SubprocessTest.cpp
folly/test/SynchronizedTestLib-inl.h
folly/test/TimeoutQueueTest.cpp
folly/test/TimeseriesHistogramTest.cpp
folly/test/VarintTest.cpp

index aef1250b434af1dfc08e6922db9c00bd0c808b23..627972ab132dc9968b5b45bab3b028455f6175bf 100644 (file)
@@ -226,7 +226,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun,
   // They key here is accuracy; too low numbers means the accuracy was
   // coarse. We up the ante until we get to at least minNanoseconds
   // timings.
-  static uint64_t resolutionInNs = 0, coarseResolutionInNs = 0;
+  static uint64_t resolutionInNs = 0;
   if (!resolutionInNs) {
     timespec ts;
     CHECK_EQ(0, clock_getres(detail::DEFAULT_CLOCK_ID, &ts));
index 1c9185d661a6dc2e6fb6fc3b23ea235cb10f13e9..79af0adaa8f907099eaaabdac608f80b917e060d 100644 (file)
@@ -20,6 +20,7 @@
 #include <cstddef>
 #include <type_traits>
 #include <limits>
+#include <glog/logging.h>
 
 #include <folly/Bits.h>
 #include <folly/Portability.h>
@@ -222,9 +223,9 @@ inline void Bits<T, Traits>::clear(T* p, size_t bit) {
 template <class T, class Traits>
 inline void Bits<T, Traits>::set(T* p, size_t bitStart, size_t count,
                                  UnderlyingType value) {
-  assert(count <= sizeof(UnderlyingType) * 8);
+  DCHECK_LE(count, sizeof(UnderlyingType) * 8);
   size_t cut = bitsPerBlock - count;
-  assert(value == (value << cut >> cut));
+  DCHECK_EQ(value, value << cut >> cut);
   size_t idx = blockIndex(bitStart);
   size_t offset = bitOffset(bitStart);
   if (std::is_signed<UnderlyingType>::value) {
@@ -266,7 +267,7 @@ inline bool Bits<T, Traits>::test(const T* p, size_t bit) {
 template <class T, class Traits>
 inline auto Bits<T, Traits>::get(const T* p, size_t bitStart, size_t count)
   -> UnderlyingType {
-  assert(count <= sizeof(UnderlyingType) * 8);
+  DCHECK_LE(count, sizeof(UnderlyingType) * 8);
   size_t idx = blockIndex(bitStart);
   size_t offset = bitOffset(bitStart);
   UnderlyingType ret;
index a0c289dadcfec8785b97a44307c8c0a5a1cd04f5..43c27b7c50a078e3065e82a38308aae0946cd20e 100644 (file)
 #include <syscall.h>
 #include <linux/futex.h>
 #include <sys/time.h>
-#include <cassert>
 #include <climits>
 #include <atomic>
 #include <thread>
+#include <glog/logging.h>
 
 #include <folly/Bits.h>
 #include <folly/Likely.h>
@@ -172,7 +172,7 @@ inline void EventCount::cancelWait() noexcept {
   // #waiters gets to 0, the less likely it is that we'll do spurious wakeups
   // (and thus system calls).
   uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
-  assert((prev & kWaiterMask) != 0);
+  DCHECK_NE((prev & kWaiterMask), 0);
 }
 
 inline void EventCount::wait(Key key) noexcept {
@@ -184,7 +184,7 @@ inline void EventCount::wait(Key key) noexcept {
   // #waiters gets to 0, the less likely it is that we'll do spurious wakeups
   // (and thus system calls)
   uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
-  assert((prev & kWaiterMask) != 0);
+  DCHECK_NE((prev & kWaiterMask), 0);
 }
 
 template <class Condition>
index 783a987659dc3945bbeb03aac6d198b9eb70a345..5674a1cacb0433f96a7b3f2ffcce66e850c87454 100644 (file)
@@ -91,7 +91,7 @@ inline void TaskIterator<T>::reserve(size_t n) {
 
 template <typename T>
 inline size_t TaskIterator<T>::getTaskID() const {
-  assert(id_ != -1);
+  assert(id_ != static_cast<size_t>(-1));
   return id_;
 }
 
index e66752acee3baa6d6853e4dc496c44a663a964e8..b4fea854afbea52ab793907c36855480ebba7e9f 100644 (file)
@@ -19,9 +19,9 @@
 #include <unistd.h>
 
 #include <algorithm>
-#include <cassert>
 #include <cstring>
 #include <stdexcept>
+#include <glog/logging.h>
 
 #include <folly/Likely.h>
 #include <folly/Portability.h>
@@ -61,7 +61,7 @@ static size_t nonMagicInBytes(const FContext& context) {
 }  // anonymous namespace
 
 void Fiber::setData(intptr_t data) {
-  assert(state_ == AWAITING);
+  DCHECK_EQ(state_, AWAITING);
   data_ = data;
   state_ = READY_TO_RUN;
 
@@ -142,19 +142,19 @@ static constexpr bool loopForever = true;
 
 void Fiber::fiberFunc() {
   while (loopForever) {
-    assert(state_ == NOT_STARTED);
+    DCHECK_EQ(state_, NOT_STARTED);
 
     threadId_ = localThreadId();
     state_ = RUNNING;
 
     try {
       if (resultFunc_) {
-        assert(finallyFunc_);
-        assert(!func_);
+        DCHECK(finallyFunc_);
+        DCHECK(!func_);
 
         resultFunc_();
       } else {
-        assert(func_);
+        DCHECK(func_);
         func_();
       }
     } catch (...) {
@@ -175,16 +175,15 @@ void Fiber::fiberFunc() {
 
     fiberManager_.activeFiber_ = nullptr;
 
-    auto fiber = reinterpret_cast<Fiber*>(
-      jumpContext(&fcontext_, &fiberManager_.mainContext_, 0));
-    assert(fiber == this);
+    auto context = jumpContext(&fcontext_, &fiberManager_.mainContext_, 0);
+    DCHECK_EQ(reinterpret_cast<Fiber*>(context), this);
   }
 }
 
 intptr_t Fiber::preempt(State state) {
-  assert(fiberManager_.activeFiber_ == this);
-  assert(state_ == RUNNING);
-  assert(state != RUNNING);
+  DCHECK_EQ(fiberManager_.activeFiber_, this);
+  DCHECK_EQ(state_, RUNNING);
+  DCHECK_NE(state, RUNNING);
 
   fiberManager_.activeFiber_ = nullptr;
   state_ = state;
@@ -193,8 +192,8 @@ intptr_t Fiber::preempt(State state) {
 
   auto ret = jumpContext(&fcontext_, &fiberManager_.mainContext_, 0);
 
-  assert(fiberManager_.activeFiber_ == this);
-  assert(state_ == READY_TO_RUN);
+  DCHECK_EQ(fiberManager_.activeFiber_, this);
+  DCHECK_EQ(state_, READY_TO_RUN);
   state_ = RUNNING;
 
   return ret;
index d931e16c4f4fe34fe69bc3c0c0640e12bf373e9b..dc1c67eb9e82dd3dc03c91f86bd607fcbc872199 100644 (file)
@@ -37,7 +37,8 @@ collectN(InputIterator first, InputIterator last, size_t n) {
   typedef typename std::result_of<
     typename std::iterator_traits<InputIterator>::value_type()>::type Result;
   assert(n > 0);
-  assert(n <= std::distance(first, last));
+  assert(std::distance(first, last) >= 0);
+  assert(n <= static_cast<size_t>(std::distance(first, last)));
 
   struct Context {
     std::vector<std::pair<size_t, Result>> results;
@@ -98,7 +99,8 @@ typename std::enable_if<
     >::value, std::vector<size_t>>::type
 collectN(InputIterator first, InputIterator last, size_t n) {
   assert(n > 0);
-  assert(n <= std::distance(first, last));
+  assert(std::distance(first, last) >= 0);
+  assert(n <= static_cast<size_t>(std::distance(first, last)));
 
   struct Context {
     std::vector<size_t> taskIndices;
index 3f323a2087d71750147b7f8b6c5ff3853f130588..6adf2831df41f242bb5d38a6295456893f968ff9 100644 (file)
@@ -205,8 +205,6 @@ TEST(FiberManager, batonTimedWaitPostEvb) {
 TEST(FiberManager, batonTryWait) {
 
   FiberManager manager(folly::make_unique<SimpleLoopController>());
-  auto& loopController =
-    dynamic_cast<SimpleLoopController&>(manager.loopController());
 
   // Check if try_wait and post work as expected
   Baton b;
@@ -1334,8 +1332,6 @@ TEST(FiberManager, yieldTest) {
 
 TEST(FiberManager, RequestContext) {
   FiberManager fm(folly::make_unique<SimpleLoopController>());
-  auto& loopController =
-    dynamic_cast<SimpleLoopController&>(fm.loopController());
 
   bool checkRun1 = false;
   bool checkRun2 = false;
@@ -1433,7 +1429,7 @@ void runBenchmark(size_t numAwaits, size_t toSend) {
               [&pendingRequests](Promise<int> promise) {
                 pendingRequests.push(std::move(promise));
               });
-            assert(result == 0);
+            DCHECK_EQ(result, 0);
           }
         });
 
index 5834f22851c5914b7305c619600addbf0624f857..4c75fa5d87cf7dcf019fdab7da33e6008380bec9 100644 (file)
@@ -616,7 +616,6 @@ TEST(Collect, collectVariadicWithException) {
   Promise<int> pi;
   Future<bool> fb = pb.getFuture();
   Future<int> fi = pi.getFuture();
-  bool flag = false;
   auto f = collect(std::move(fb), std::move(fi));
   pb.setValue(true);
   EXPECT_FALSE(f.isReady());
index 7937e4004dc9a2d84468377c87b06d9e24cfd51b..206f455765fab3d2e366901196ee0d1e9d1dccf8 100644 (file)
@@ -61,7 +61,6 @@ void AsyncPipeReader::handlerReady(uint16_t events) noexcept {
   VLOG(5) << "AsyncPipeReader::handlerReady() this=" << this << ", fd=" << fd_;
   assert(readCallback_ != nullptr);
 
-  uint16_t numReads = 0;
   while (readCallback_) {
     // Get the buffer to read into.
     void* buf = nullptr;
index f6f13e7585759615f885ea16d16c815fa6cfd6db..ae078401c59d1e811230a7446790770629adfba2 100644 (file)
@@ -326,6 +326,8 @@ void AsyncSSLSocket::init() {
   // Do this here to ensure we initialize this once before any use of
   // AsyncSSLSocket instances and not as part of library load.
   static const auto eorAwareBioMethodInitializer = initEorBioMethod();
+  (void)eorAwareBioMethodInitializer;
+
   setup_SSL_CTX(ctx_->getSSLCtx());
 }
 
index f9624f058189456593539faee614c32046ce5473..182d92cd33ff80115ce9c8d665a6f41c8d7d419c 100644 (file)
@@ -76,6 +76,7 @@ ctx_(new folly::SSLContext),
 
   int ret = pthread_create(&thread_, nullptr, Main, this);
   assert(ret == 0);
+  (void)ret;
 
   std::cerr << "Accepting connections on " << address_ << std::endl;
 }
@@ -208,6 +209,7 @@ TEST(AsyncSSLSocketTest, HandshakeError) {
 
     uint8_t readbuf[128];
     uint32_t bytesRead = socket->readAll(readbuf, sizeof(readbuf));
+    LOG(ERROR) << "readAll returned " << bytesRead << " instead of throwing";
   } catch (AsyncSocketException &e) {
     ex = true;
   }
index 695b6e7d10097dc651f74149723bc0ce69a69351..30ee8e9090177e109b57780728db0d2c6f6b62bb 100644 (file)
@@ -75,8 +75,6 @@ struct HHWheelTimerTest : public ::testing::Test {
 TEST_F(HHWheelTimerTest, FireOnce) {
   StackWheelTimer t(&eventBase, milliseconds(1));
 
-  const HHWheelTimer::Callback* nullCallback = nullptr;
-
   TestTimeout t1;
   TestTimeout t2;
   TestTimeout t3;
@@ -113,7 +111,6 @@ TEST_F(HHWheelTimerTest, FireOnce) {
  */
 TEST_F(HHWheelTimerTest, TestSchedulingWithinCallback) {
   StackWheelTimer t(&eventBase, milliseconds(10));
-  const HHWheelTimer::Callback* nullCallback = nullptr;
 
   TestTimeout t1;
   // Delayed to simulate the steady_clock counter lagging
index 392f87b18fb3a3f96c74934c8ab3efca207d0bb1..86aad240f1466c82f42625f57efdd91c8e93b882 100644 (file)
@@ -40,7 +40,7 @@ TEST(IOBuf, RWCursor) {
   unique_ptr<IOBuf> iobuf2(IOBuf::create(20));
   iobuf2->append(20);
 
-  IOBuf* iob2ptr = iobuf2.get();
+  iobuf2.get();
   iobuf1->prependChain(std::move(iobuf2));
 
   EXPECT_TRUE(iobuf1->isChained());
@@ -772,7 +772,6 @@ BENCHMARK(cursorBenchmark, iters) {
 }
 
 BENCHMARK(skipBenchmark, iters) {
-  uint8_t buf;
   while (iters--) {
     Cursor c(iobuf_read_benchmark.get());
     for(int i = 0; i < benchmark_size ; i++) {
index 1106c515ca4a726984aa9ddce7578a8704618317..8afed780a683cc2fe0822a8b5a7c13a601b3e5e2 100644 (file)
@@ -156,7 +156,6 @@ TEST(IOBufQueue, Split) {
   queue.append(stringToIOBuf(SCL("Hello,")));
   queue.append(stringToIOBuf(SCL(" World")));
   checkConsistency(queue);
-  bool exceptionFired = false;
   EXPECT_THROW({prefix = queue.split(13);}, std::underflow_error);
   checkConsistency(queue);
 }
index ba92617752daa525c5b864aa6159ea034939db91..25d7a9b0e7f8a20a6d62b75b92d56c4d1ca0d93e 100644 (file)
@@ -628,7 +628,6 @@ TEST(IOBuf, Reserve) {
     EXPECT_EQ(0, iob->headroom());
     EXPECT_EQ(100, iob->length());
     const void* p1 = iob->buffer();
-    const uint8_t* d1 = iob->data();
     iob->reserve(100, 2512);  // allocation sizes are multiples of 256
     EXPECT_LE(100, iob->headroom());
     if (folly::usingJEMalloc()) {
index 0a65d361494aa7babdcd950e777baceb9a5c5e48..e173a4f49909766cbb75c29320b93e5f3dafafb5 100644 (file)
@@ -138,8 +138,6 @@ TEST(Ahm, grow) {
   EXPECT_TRUE(success);
 
   // check correctness
-  size_t cap = m->capacity();
-  ValueT val;
   EXPECT_GT(m->numSubMaps(), 1);  // make sure we grew
   success = true;
   EXPECT_EQ(m->size(), numEntries);
@@ -150,7 +148,6 @@ TEST(Ahm, grow) {
 
   // Check findAt
   success = true;
-  KeyT key(0);
   AHMapT::const_iterator retIt;
   for (int32_t i = 0; i < int32_t(numEntries); i++) {
     retIt = m->find(i);
@@ -431,7 +428,6 @@ TEST(Ahm, collision_test) {
   // check correctness
   EXPECT_EQ(sizeAHM, numInserts);
   bool success = true;
-  ValueT val;
   for (int i = 0; i < numInserts; ++i) {
     KeyT key = randomizeKey(i);
     success &= (globalAHM->find(key)->second == genVal(key));
@@ -459,8 +455,7 @@ namespace {
 const int kInsertPerThread = 100000;
 int raceFinalSizeEstimate;
 
-void* raceIterateThread(void* jj) {
-  int64_t j = (int64_t) jj;
+void* raceIterateThread(void*) {
   int count = 0;
 
   AHMapT::iterator it = globalAHM->begin();
@@ -475,8 +470,7 @@ void* raceIterateThread(void* jj) {
   return nullptr;
 }
 
-void* raceInsertRandomThread(void* jj) {
-  int64_t j = (int64_t) jj;
+void* raceInsertRandomThread(void*) {
   for (int i = 0; i < kInsertPerThread; ++i) {
     KeyT key = rand();
     globalAHM->insert(key, genVal(key));
@@ -499,11 +493,11 @@ TEST(Ahm, race_insert_iterate_thread_test) {
   globalAHM.reset(new AHMapT(raceFinalSizeEstimate / 9, config));
 
   vector<pthread_t> threadIds;
-  for (int64_t j = 0; j < kInsertThreads + kIterateThreads; j++) {
+  for (int j = 0; j < kInsertThreads + kIterateThreads; j++) {
     pthread_t tid;
     void *(*thread)(void*) =
       (j < kInsertThreads ? raceInsertRandomThread : raceIterateThread);
-    if (pthread_create(&tid, nullptr, thread, (void*) j) != 0) {
+    if (pthread_create(&tid, nullptr, thread, nullptr) != 0) {
       LOG(ERROR) << "Could not start thread";
     } else {
       threadIds.push_back(tid);
index 625a651dee17b15e4466ebfb8b5a0f9ad2a087f8..8967a7d0f0a454a66739a1de33b2467a4d4a5fd9 100644 (file)
 using namespace std;
 using namespace folly;
 
-static int8_t s8;
-static uint8_t u8;
-static int16_t s16;
-static uint16_t u16;
-static int32_t s32;
-static uint32_t u32;
-static int64_t s64;
-static uint64_t u64;
+
 
 TEST(Conv, digits10Minimal) {
   // Not much of a test (and it's included in the test below anyway).
@@ -124,7 +117,7 @@ TEST(Conv, Type2Type) {
 
 TEST(Conv, Integral2Integral) {
   // Same size, different signs
-  s64 = numeric_limits<uint8_t>::max();
+  int64_t s64 = numeric_limits<uint8_t>::max();
   EXPECT_EQ(to<uint8_t>(s64), s64);
 
   s64 = numeric_limits<int8_t>::max();
@@ -644,6 +637,7 @@ TEST(Conv, DoubleToInt) {
   EXPECT_EQ(i, 42);
   try {
     auto i = to<int>(42.1);
+    LOG(ERROR) << "to<int> returned " << i << " instead of throwing";
     EXPECT_TRUE(false);
   } catch (std::range_error& e) {
     //LOG(INFO) << e.what();
@@ -658,7 +652,9 @@ TEST(Conv, EnumToInt) {
   EXPECT_EQ(j, 42);
   try {
     auto i = to<char>(y);
-    LOG(ERROR) << static_cast<unsigned int>(i);
+    LOG(ERROR) << "to<char> returned "
+               << static_cast<unsigned int>(i)
+               << " instead of throwing";
     EXPECT_TRUE(false);
   } catch (std::range_error& e) {
     //LOG(INFO) << e.what();
@@ -681,6 +677,9 @@ TEST(Conv, IntToEnum) {
   EXPECT_EQ(j, 100);
   try {
     auto i = to<A>(5000000000L);
+    LOG(ERROR) << "to<A> returned "
+               << static_cast<unsigned int>(i)
+               << " instead of throwing";
     EXPECT_TRUE(false);
   } catch (std::range_error& e) {
     //LOG(INFO) << e.what();
@@ -697,7 +696,7 @@ TEST(Conv, UnsignedEnum) {
   EXPECT_EQ(e, x);
   try {
     auto i = to<int32_t>(x);
-    LOG(ERROR) << to<uint32_t>(x);
+    LOG(ERROR) << "to<int32_t> returned " << i << " instead of throwing";
     EXPECT_TRUE(false);
   } catch (std::range_error& e) {
   }
@@ -714,7 +713,7 @@ TEST(Conv, UnsignedEnumClass) {
   EXPECT_EQ(e, E::x);
   try {
     auto i = to<int32_t>(E::x);
-    LOG(ERROR) << to<uint32_t>(E::x);
+    LOG(ERROR) << "to<int32_t> returned " << i << " instead of throwing";
     EXPECT_TRUE(false);
   } catch (std::range_error& e) {
   }
index 42cf192936c950d0373554aa684333d9ee1ea741..62a2fbf5eb91badb45b7f184d213a078709f37d3 100644 (file)
@@ -254,7 +254,6 @@ FutexResult Futex<DeterministicAtomic>::futexWaitImpl(
   bool hasTimeout = absSystemTimeout != nullptr || absSteadyTimeout != nullptr;
   bool awoken = false;
   FutexResult result = FutexResult::AWOKEN;
-  int futexErrno = 0;
 
   DeterministicSchedule::beforeSharedAccess();
   FOLLY_TEST_DSCHED_VLOG(this << ".futexWait(" << std::hex << expected
index e043d9142a1842aa7b428ad8d3d299ef5f482d73..f9360f0212bc2b571286ecb5323268963302fd7c 100644 (file)
@@ -235,6 +235,9 @@ TEST(Dynamic, Operator) {
     dynamic d1 = dynamic::object;
     dynamic d2 = dynamic::object;
     auto foo = d1 < d2;
+    LOG(ERROR) << "operator < returned "
+               << static_cast<int>(foo)
+               << " instead of throwing";
   } catch (std::exception const& e) {
     caught = true;
   }
index 315b3e4acd9c299bcf2b5b0ff82ef8801ce81977..e548a8d57dad69e4345acbc9198f4fe43218f0aa 100644 (file)
@@ -119,9 +119,7 @@ template <class String> void clause11_21_4_2_e(String & test) {
 }
 template <class String> void clause11_21_4_2_f(String & test) {
   // Constructor from char*
-  const size_t
-    pos = random(0, test.size()),
-    n = random(0, test.size() - pos);
+  const size_t pos = random(0, test.size());
   String before(test.data(), test.size());
   String s(test.c_str() + pos);
   String after(test.data(), test.size());
index 3a120c54c68637dc8986002337ccabe7a4bd7ccd..9ee40bbd6de83f263fc16493faf77e5e5655433d 100644 (file)
@@ -35,11 +35,11 @@ namespace {
 void expectWouldBlock(ssize_t r) {
   int savedErrno = errno;
   EXPECT_EQ(-1, r);
-  EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(errno);
+  EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(savedErrno);
 }
 void expectOK(ssize_t r) {
   int savedErrno = errno;
-  EXPECT_LE(0, r) << ": errno=" << errnoStr(errno);
+  EXPECT_LE(0, r) << ": errno=" << errnoStr(savedErrno);
 }
 }  // namespace
 
index 4c13b93795d2563b03b8d1eba0f987dd43b690d1..4d97b0b0ddfdbd1509ab03b3ef3f76f20286429a 100644 (file)
@@ -188,8 +188,6 @@ BENCHMARK(ForEachKVNoMacroAssign, iters) {
 
   BENCHMARK_SUSPEND {
     setupBenchmark(iters);
-    int sumKeys = 0;
-    std::string sumValues = "";
   }
 
   FOR_EACH (iter, bmMap) {
@@ -215,11 +213,12 @@ BENCHMARK(ForEachKVNoMacroNoAssign, iters) {
 }
 
 BENCHMARK(ManualLoopNoAssign, iters) {
+  int sumKeys = 0;
+  std::string sumValues;
+
   BENCHMARK_SUSPEND {
     setupBenchmark(iters);
   }
-  int sumKeys = 0;
-  std::string sumValues;
 
   for (auto iter = bmMap.begin(); iter != bmMap.end(); ++iter) {
     sumKeys += iter->first;
@@ -228,11 +227,12 @@ BENCHMARK(ManualLoopNoAssign, iters) {
 }
 
 BENCHMARK(ForEachKVMacro, iters) {
+  int sumKeys = 0;
+  std::string sumValues;
+
   BENCHMARK_SUSPEND {
     setupBenchmark(iters);
   }
-  int sumKeys = 0;
-  std::string sumValues;
 
   FOR_EACH_KV (k, v, bmMap) {
     sumKeys += k;
index 8676180fd2f6484fb271203cea2abf04ca5d07ef..85c8d8fbaeccd0bb30a55ba23b8fd01eb525436c 100644 (file)
@@ -201,7 +201,6 @@ TEST(Format, Simple) {
 }
 
 TEST(Format, Float) {
-  double d = 1;
   EXPECT_EQ("1", sformat("{}", 1.0));
   EXPECT_EQ("0.1", sformat("{}", 0.1));
   EXPECT_EQ("0.01", sformat("{}", 0.01));
index cb1bc108c0a0f4ff5e890244573d42e845daa9c1..ef7885683623c1e0744475949c30c997aabebf53 100644 (file)
@@ -506,7 +506,6 @@ static vector<pair<string, uint8_t> > invalidMasks = {
 };
 TEST(IPAddress, InvalidMask) {
   for (auto& tc : invalidMasks) {
-    uint8_t mask = tc.second;
     auto ip = IPAddress(tc.first);
     EXPECT_THROW(ip.mask(tc.second), IPAddressFormatException);
   }
index 974c8f422f6fa03cdc1c981919e4e440473df254..42fd4926808156978f27a07c0425546fa492e85c 100644 (file)
@@ -117,7 +117,11 @@ public:
     other.s_ = "";
   }
   MoveTester& operator=(const MoveTester&) = default;
-  MoveTester& operator=(MoveTester&&) = default;
+  MoveTester& operator=(MoveTester&& other) noexcept {
+    s_ = std::move(other.s_);
+    other.s_ = "";
+    return *this;
+  }
 private:
   friend bool operator==(const MoveTester& o1, const MoveTester& o2);
   std::string s_;
@@ -398,6 +402,7 @@ TEST(Optional, Conversions) {
 
   // intended explicit operator bool, for if (opt).
   bool b(mbool);
+  EXPECT_FALSE(b);
 
   // Truthy tests work and are not ambiguous
   if (mbool && mshort && mstr && mint) { // only checks not-empty
index 276d57119ebcf6a2b584ef5a5ce4cd4cd4f8a069..f92cbe3e4be6db6c1da7df960276ad03c2a1b876 100644 (file)
@@ -478,9 +478,11 @@ static void runContendedReaders(size_t numOps,
                                 size_t numThreads,
                                 bool useSeparateLocks) {
   char padding1[64];
+  (void)padding1;
   Lock globalLock;
   int valueProtectedByLock = 10;
   char padding2[64];
+  (void)padding2;
   Atom<bool> go(false);
   Atom<bool>* goPtr = &go; // workaround for clang bug
   vector<thread> threads(numThreads);
@@ -575,9 +577,11 @@ static void runMixed(size_t numOps,
                      double writeFraction,
                      bool useSeparateLocks) {
   char padding1[64];
+  (void)padding1;
   Lock globalLock;
   int valueProtectedByLock = 0;
   char padding2[64];
+  (void)padding2;
   Atom<bool> go(false);
   Atom<bool>* goPtr = &go; // workaround for clang bug
   vector<thread> threads(numThreads);
@@ -598,7 +602,6 @@ static void runMixed(size_t numOps,
           long randVal;
           lrand48_r(&buffer, &randVal);
           bool writeOp = randVal < writeThreshold;
-          SharedMutexToken token;
           if (writeOp) {
             locker.lock(lock);
             if (!useSeparateLocks) {
@@ -1227,8 +1230,10 @@ static void burn(size_t n) {
 template <typename Lock, template <typename> class Atom = atomic>
 static void runPingPong(size_t numRounds, size_t burnCount) {
   char padding1[56];
+  (void)padding1;
   pair<Lock, char[56]> locks[3];
   char padding2[56];
+  (void)padding2;
 
   Atom<int> avail(0);
   auto availPtr = &avail; // workaround for clang crash
index 55152751567bcc7d00a7849aabc1f8afb943ea2a..fe14d2aa82916ca98ff5cbd7b9d0721734483152 100644 (file)
@@ -387,7 +387,7 @@ template <typename T, typename Tag = detail::DefaultTag>
 using SingletonCreationError = Singleton<T, Tag, CreationErrorTag>;
 
 TEST(Singleton, SingletonCreationError) {
-  auto& vault = *SingletonVault::singleton<CreationErrorTag>();
+  SingletonVault::singleton<CreationErrorTag>();
   SingletonCreationError<ErrorConstructor> error_once_singleton;
 
   // first time should error out
index 3b88f5aae571430adac2438204a4af54ee8fcf53..792a9cac432b53d1fdc23b569c6075db756ca238 100644 (file)
@@ -345,8 +345,6 @@ TEST(CommunicateSubprocessTest, Duplex2) {
 namespace {
 
 bool readToString(int fd, std::string& buf, size_t maxSize) {
-  size_t bytesRead = 0;
-
   buf.resize(maxSize);
   char* dest = &buf.front();
   size_t remaining = maxSize;
index bee27f9a5cf5e6b47d1a3ba6d33f8d430b81f3fa..ef4045c8c4242b8d4e0e511ac7f627cc138f1ad4 100644 (file)
@@ -188,12 +188,12 @@ template <class Mutex> void testDualLockingWithConst() {
 
       if (i & 1) {
         SYNCHRONIZED_DUAL (v, pv, m, pm) {
-          size_t s = m.size();
+          (void)m.size();
           v.push_back(i);
         }
       } else {
         SYNCHRONIZED_DUAL (m, pm, v, pv) {
-          size_t s = m.size();
+          (void)m.size();
           v.push_back(i);
         }
       }
index 1c578dfc0b94ea864de60203750254a68f79d406..07c08105e0438fe4ace9a65b3d8675d67f2508d4 100644 (file)
@@ -102,7 +102,6 @@ TEST(TimeoutQueue, RunOnceReschedule) {
 
   EXPECT_EQ(1, q.add(0, 0, cb));
 
-  int64_t now = 0;
   EXPECT_EQ(0, q.runOnce(0));
   EXPECT_EQ(1, count);
   EXPECT_EQ(0, q.runOnce(0));
index 85e3198edb43dc36837b3ffadfc7a312a3935ff1..16c1629cc219b42484b78dde5303471185c7dfff 100644 (file)
@@ -428,7 +428,6 @@ TEST(TimeseriesHistogram, QueryByInterval) {
 
   for (int i = 0; i < 12; i++) {
     const auto& itv = intervals[i];
-    int c = mhts.count(itv.start, itv.end);
     // Some of the older intervals that fall in the alltime bucket
     // are off by 1 or 2 in their estimated counts.
     size_t tolerance = 0;
index 22076affeb9d5d842fc5b7e34d9575beb87e9ac0..5c0bcf57484491d24b50e8e5627d73a575e0a648 100644 (file)
@@ -163,7 +163,6 @@ void generateRandomValues() {
 BENCHMARK(VarintEncoding, iters) {
   uint8_t* start = &(*gEncoded.begin());
   uint8_t* p = start;
-  bool empty = (iters == 0);
   while (iters--) {
     p = start;
     for (auto& v : gValues) {