Commit b05969e4 authored by Nathan Bronson's avatar Nathan Bronson Committed by facebook-github-bot-5

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