From b05969e4b4474cadf1cb1f8ebc37567cc63c9b88 Mon Sep 17 00:00:00 2001 From: Nathan Bronson Date: Thu, 1 Oct 2015 18:39:47 -0700 Subject: [PATCH] fix compiler warnings from gcc-4.9 + -Wunused-variable 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 --- folly/Benchmark.cpp | 2 +- folly/experimental/Bits.h | 7 ++--- folly/experimental/EventCount.h | 6 ++--- folly/experimental/fibers/AddTasks-inl.h | 2 +- folly/experimental/fibers/Fiber.cpp | 27 +++++++++---------- folly/experimental/fibers/WhenN-inl.h | 6 +++-- folly/experimental/fibers/test/FibersTest.cpp | 6 +---- folly/futures/test/CollectTest.cpp | 1 - folly/io/async/AsyncPipe.cpp | 1 - folly/io/async/AsyncSSLSocket.cpp | 2 ++ folly/io/async/test/AsyncSSLSocketTest.cpp | 2 ++ folly/io/async/test/HHWheelTimerTest.cpp | 3 --- folly/io/test/IOBufCursorTest.cpp | 3 +-- folly/io/test/IOBufQueueTest.cpp | 1 - folly/io/test/IOBufTest.cpp | 1 - folly/test/AtomicHashMapTest.cpp | 14 +++------- folly/test/ConvTest.cpp | 23 ++++++++-------- folly/test/DeterministicSchedule.cpp | 1 - folly/test/DynamicTest.cpp | 3 +++ folly/test/FBStringTest.cpp | 4 +-- folly/test/FileTest.cpp | 4 +-- folly/test/ForeachTest.cpp | 12 ++++----- folly/test/FormatTest.cpp | 1 - folly/test/IPAddressTest.cpp | 1 - folly/test/OptionalTest.cpp | 7 ++++- folly/test/SharedMutexTest.cpp | 7 ++++- folly/test/SingletonTest.cpp | 2 +- folly/test/SubprocessTest.cpp | 2 -- folly/test/SynchronizedTestLib-inl.h | 4 +-- folly/test/TimeoutQueueTest.cpp | 1 - folly/test/TimeseriesHistogramTest.cpp | 1 - folly/test/VarintTest.cpp | 1 - 32 files changed, 74 insertions(+), 84 deletions(-) diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index aef1250b..627972ab 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -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)); diff --git a/folly/experimental/Bits.h b/folly/experimental/Bits.h index 1c9185d6..79af0ada 100644 --- a/folly/experimental/Bits.h +++ b/folly/experimental/Bits.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -222,9 +223,9 @@ inline void Bits::clear(T* p, size_t bit) { template inline void Bits::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::value) { @@ -266,7 +267,7 @@ inline bool Bits::test(const T* p, size_t bit) { template inline auto Bits::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; diff --git a/folly/experimental/EventCount.h b/folly/experimental/EventCount.h index a0c289da..43c27b7c 100644 --- a/folly/experimental/EventCount.h +++ b/folly/experimental/EventCount.h @@ -21,10 +21,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -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 diff --git a/folly/experimental/fibers/AddTasks-inl.h b/folly/experimental/fibers/AddTasks-inl.h index 783a9876..5674a1ca 100644 --- a/folly/experimental/fibers/AddTasks-inl.h +++ b/folly/experimental/fibers/AddTasks-inl.h @@ -91,7 +91,7 @@ inline void TaskIterator::reserve(size_t n) { template inline size_t TaskIterator::getTaskID() const { - assert(id_ != -1); + assert(id_ != static_cast(-1)); return id_; } diff --git a/folly/experimental/fibers/Fiber.cpp b/folly/experimental/fibers/Fiber.cpp index e66752ac..b4fea854 100644 --- a/folly/experimental/fibers/Fiber.cpp +++ b/folly/experimental/fibers/Fiber.cpp @@ -19,9 +19,9 @@ #include #include -#include #include #include +#include #include #include @@ -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( - jumpContext(&fcontext_, &fiberManager_.mainContext_, 0)); - assert(fiber == this); + auto context = jumpContext(&fcontext_, &fiberManager_.mainContext_, 0); + DCHECK_EQ(reinterpret_cast(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; diff --git a/folly/experimental/fibers/WhenN-inl.h b/folly/experimental/fibers/WhenN-inl.h index d931e16c..dc1c67eb 100644 --- a/folly/experimental/fibers/WhenN-inl.h +++ b/folly/experimental/fibers/WhenN-inl.h @@ -37,7 +37,8 @@ collectN(InputIterator first, InputIterator last, size_t n) { typedef typename std::result_of< typename std::iterator_traits::value_type()>::type Result; assert(n > 0); - assert(n <= std::distance(first, last)); + assert(std::distance(first, last) >= 0); + assert(n <= static_cast(std::distance(first, last))); struct Context { std::vector> results; @@ -98,7 +99,8 @@ typename std::enable_if< >::value, std::vector>::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(std::distance(first, last))); struct Context { std::vector taskIndices; diff --git a/folly/experimental/fibers/test/FibersTest.cpp b/folly/experimental/fibers/test/FibersTest.cpp index 3f323a20..6adf2831 100644 --- a/folly/experimental/fibers/test/FibersTest.cpp +++ b/folly/experimental/fibers/test/FibersTest.cpp @@ -205,8 +205,6 @@ TEST(FiberManager, batonTimedWaitPostEvb) { TEST(FiberManager, batonTryWait) { FiberManager manager(folly::make_unique()); - auto& loopController = - dynamic_cast(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()); - auto& loopController = - dynamic_cast(fm.loopController()); bool checkRun1 = false; bool checkRun2 = false; @@ -1433,7 +1429,7 @@ void runBenchmark(size_t numAwaits, size_t toSend) { [&pendingRequests](Promise promise) { pendingRequests.push(std::move(promise)); }); - assert(result == 0); + DCHECK_EQ(result, 0); } }); diff --git a/folly/futures/test/CollectTest.cpp b/folly/futures/test/CollectTest.cpp index 5834f228..4c75fa5d 100644 --- a/folly/futures/test/CollectTest.cpp +++ b/folly/futures/test/CollectTest.cpp @@ -616,7 +616,6 @@ TEST(Collect, collectVariadicWithException) { Promise pi; Future fb = pb.getFuture(); Future fi = pi.getFuture(); - bool flag = false; auto f = collect(std::move(fb), std::move(fi)); pb.setValue(true); EXPECT_FALSE(f.isReady()); diff --git a/folly/io/async/AsyncPipe.cpp b/folly/io/async/AsyncPipe.cpp index 7937e400..206f4557 100644 --- a/folly/io/async/AsyncPipe.cpp +++ b/folly/io/async/AsyncPipe.cpp @@ -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; diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index f6f13e75..ae078401 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -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()); } diff --git a/folly/io/async/test/AsyncSSLSocketTest.cpp b/folly/io/async/test/AsyncSSLSocketTest.cpp index f9624f05..182d92cd 100644 --- a/folly/io/async/test/AsyncSSLSocketTest.cpp +++ b/folly/io/async/test/AsyncSSLSocketTest.cpp @@ -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; } diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 695b6e7d..30ee8e90 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -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 diff --git a/folly/io/test/IOBufCursorTest.cpp b/folly/io/test/IOBufCursorTest.cpp index 392f87b1..86aad240 100644 --- a/folly/io/test/IOBufCursorTest.cpp +++ b/folly/io/test/IOBufCursorTest.cpp @@ -40,7 +40,7 @@ TEST(IOBuf, RWCursor) { unique_ptr 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++) { diff --git a/folly/io/test/IOBufQueueTest.cpp b/folly/io/test/IOBufQueueTest.cpp index 1106c515..8afed780 100644 --- a/folly/io/test/IOBufQueueTest.cpp +++ b/folly/io/test/IOBufQueueTest.cpp @@ -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); } diff --git a/folly/io/test/IOBufTest.cpp b/folly/io/test/IOBufTest.cpp index ba926177..25d7a9b0 100644 --- a/folly/io/test/IOBufTest.cpp +++ b/folly/io/test/IOBufTest.cpp @@ -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()) { diff --git a/folly/test/AtomicHashMapTest.cpp b/folly/test/AtomicHashMapTest.cpp index 0a65d361..e173a4f4 100644 --- a/folly/test/AtomicHashMapTest.cpp +++ b/folly/test/AtomicHashMapTest.cpp @@ -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 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); diff --git a/folly/test/ConvTest.cpp b/folly/test/ConvTest.cpp index 625a651d..8967a7d0 100644 --- a/folly/test/ConvTest.cpp +++ b/folly/test/ConvTest.cpp @@ -25,14 +25,7 @@ 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::max(); + int64_t s64 = numeric_limits::max(); EXPECT_EQ(to(s64), s64); s64 = numeric_limits::max(); @@ -644,6 +637,7 @@ TEST(Conv, DoubleToInt) { EXPECT_EQ(i, 42); try { auto i = to(42.1); + LOG(ERROR) << "to 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(y); - LOG(ERROR) << static_cast(i); + LOG(ERROR) << "to returned " + << static_cast(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(5000000000L); + LOG(ERROR) << "to returned " + << static_cast(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(x); - LOG(ERROR) << to(x); + LOG(ERROR) << "to 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(E::x); - LOG(ERROR) << to(E::x); + LOG(ERROR) << "to returned " << i << " instead of throwing"; EXPECT_TRUE(false); } catch (std::range_error& e) { } diff --git a/folly/test/DeterministicSchedule.cpp b/folly/test/DeterministicSchedule.cpp index 42cf1929..62a2fbf5 100644 --- a/folly/test/DeterministicSchedule.cpp +++ b/folly/test/DeterministicSchedule.cpp @@ -254,7 +254,6 @@ FutexResult Futex::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 diff --git a/folly/test/DynamicTest.cpp b/folly/test/DynamicTest.cpp index e043d914..f9360f02 100644 --- a/folly/test/DynamicTest.cpp +++ b/folly/test/DynamicTest.cpp @@ -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(foo) + << " instead of throwing"; } catch (std::exception const& e) { caught = true; } diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 315b3e4a..e548a8d5 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -119,9 +119,7 @@ template void clause11_21_4_2_e(String & test) { } template 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()); diff --git a/folly/test/FileTest.cpp b/folly/test/FileTest.cpp index 3a120c54..9ee40bbd 100644 --- a/folly/test/FileTest.cpp +++ b/folly/test/FileTest.cpp @@ -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 diff --git a/folly/test/ForeachTest.cpp b/folly/test/ForeachTest.cpp index 4c13b937..4d97b0b0 100644 --- a/folly/test/ForeachTest.cpp +++ b/folly/test/ForeachTest.cpp @@ -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; diff --git a/folly/test/FormatTest.cpp b/folly/test/FormatTest.cpp index 8676180f..85c8d8fb 100644 --- a/folly/test/FormatTest.cpp +++ b/folly/test/FormatTest.cpp @@ -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)); diff --git a/folly/test/IPAddressTest.cpp b/folly/test/IPAddressTest.cpp index cb1bc108..ef788568 100644 --- a/folly/test/IPAddressTest.cpp +++ b/folly/test/IPAddressTest.cpp @@ -506,7 +506,6 @@ static vector > 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); } diff --git a/folly/test/OptionalTest.cpp b/folly/test/OptionalTest.cpp index 974c8f42..42fd4926 100644 --- a/folly/test/OptionalTest.cpp +++ b/folly/test/OptionalTest.cpp @@ -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 diff --git a/folly/test/SharedMutexTest.cpp b/folly/test/SharedMutexTest.cpp index 276d5711..f92cbe3e 100644 --- a/folly/test/SharedMutexTest.cpp +++ b/folly/test/SharedMutexTest.cpp @@ -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 go(false); Atom* goPtr = &go; // workaround for clang bug vector 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 go(false); Atom* goPtr = &go; // workaround for clang bug vector 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 class Atom = atomic> static void runPingPong(size_t numRounds, size_t burnCount) { char padding1[56]; + (void)padding1; pair locks[3]; char padding2[56]; + (void)padding2; Atom avail(0); auto availPtr = &avail; // workaround for clang crash diff --git a/folly/test/SingletonTest.cpp b/folly/test/SingletonTest.cpp index 55152751..fe14d2aa 100644 --- a/folly/test/SingletonTest.cpp +++ b/folly/test/SingletonTest.cpp @@ -387,7 +387,7 @@ template using SingletonCreationError = Singleton; TEST(Singleton, SingletonCreationError) { - auto& vault = *SingletonVault::singleton(); + SingletonVault::singleton(); SingletonCreationError error_once_singleton; // first time should error out diff --git a/folly/test/SubprocessTest.cpp b/folly/test/SubprocessTest.cpp index 3b88f5aa..792a9cac 100644 --- a/folly/test/SubprocessTest.cpp +++ b/folly/test/SubprocessTest.cpp @@ -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; diff --git a/folly/test/SynchronizedTestLib-inl.h b/folly/test/SynchronizedTestLib-inl.h index bee27f9a..ef4045c8 100644 --- a/folly/test/SynchronizedTestLib-inl.h +++ b/folly/test/SynchronizedTestLib-inl.h @@ -188,12 +188,12 @@ template 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); } } diff --git a/folly/test/TimeoutQueueTest.cpp b/folly/test/TimeoutQueueTest.cpp index 1c578dfc..07c08105 100644 --- a/folly/test/TimeoutQueueTest.cpp +++ b/folly/test/TimeoutQueueTest.cpp @@ -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)); diff --git a/folly/test/TimeseriesHistogramTest.cpp b/folly/test/TimeseriesHistogramTest.cpp index 85e3198e..16c1629c 100644 --- a/folly/test/TimeseriesHistogramTest.cpp +++ b/folly/test/TimeseriesHistogramTest.cpp @@ -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; diff --git a/folly/test/VarintTest.cpp b/folly/test/VarintTest.cpp index 22076aff..5c0bcf57 100644 --- a/folly/test/VarintTest.cpp +++ b/folly/test/VarintTest.cpp @@ -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) { -- 2.34.1