From 2750533d9c7ab53ba6046ca9b50e7dceb7a73680 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 16 May 2017 08:07:22 -0700 Subject: [PATCH] Fix violations of unused-lambda-capture Summary: [Folly] Fix violations of `unused-lambda-capture`. Reviewed By: Orvid Differential Revision: D5060391 fbshipit-source-id: 34aabc847719603d13da8f2b52a7ec187d803a4a --- .../experimental/test/AtomicSharedPtrTest.cpp | 2 +- folly/experimental/test/RefCountTest.cpp | 36 +++++++++---------- folly/fibers/test/FibersTest.cpp | 15 ++++---- folly/futures/test/BarrierTest.cpp | 32 ++++++++--------- folly/futures/test/FutureTest.cpp | 5 ++- folly/io/async/test/EventBaseTest.cpp | 2 +- folly/io/async/test/HHWheelTimerSlowTests.cpp | 2 +- folly/io/test/CompressionTest.cpp | 17 +++++---- folly/test/AHMIntStressTest.cpp | 16 ++++----- folly/test/AtomicLinkedListTest.cpp | 11 +++--- folly/test/FunctionTest.cpp | 5 ++- folly/test/MPMCPipelineTest.cpp | 4 +-- folly/test/SingletonThreadLocalTest.cpp | 15 ++++---- folly/test/SmallLocksBenchmark.cpp | 4 +-- folly/test/ThreadLocalTest.cpp | 6 ++-- 15 files changed, 86 insertions(+), 86 deletions(-) diff --git a/folly/experimental/test/AtomicSharedPtrTest.cpp b/folly/experimental/test/AtomicSharedPtrTest.cpp index 9598d969..06b42d8a 100644 --- a/folly/experimental/test/AtomicSharedPtrTest.cpp +++ b/folly/experimental/test/AtomicSharedPtrTest.cpp @@ -156,7 +156,7 @@ TEST(AtomicSharedPtr, DeterministicTest) { fooptr(foo); std::vector threads(FLAGS_num_threads); for (int tid = 0; tid < FLAGS_num_threads; ++tid) { - threads[tid] = DSched::thread([&, tid]() { + threads[tid] = DSched::thread([&]() { for (int i = 0; i < 1000; i++) { auto l = fooptr.load(); EXPECT_TRUE(l.get() != nullptr); diff --git a/folly/experimental/test/RefCountTest.cpp b/folly/experimental/test/RefCountTest.cpp index 13907ca3..65c338a5 100644 --- a/folly/experimental/test/RefCountTest.cpp +++ b/folly/experimental/test/RefCountTest.cpp @@ -36,29 +36,29 @@ void basicTest() { std::vector ts; folly::Baton<> threadBatons[numThreads]; for (size_t t = 0; t < numThreads; ++t) { - ts.emplace_back([&count, &b, &got0, numIters, t, &threadBatons]() { - for (size_t i = 0; i < numIters; ++i) { - auto ret = ++count; - - EXPECT_TRUE(ret > 1); - if (i == 0) { - threadBatons[t].post(); - } - } + ts.emplace_back([&count, &b, &got0, t, &threadBatons] { + for (size_t i = 0; i < numIters; ++i) { + auto ret = ++count; - if (t == 0) { - b.post(); + EXPECT_TRUE(ret > 1); + if (i == 0) { + threadBatons[t].post(); } + } + + if (t == 0) { + b.post(); + } - for (size_t i = 0; i < numIters; ++i) { - auto ret = --count; + for (size_t i = 0; i < numIters; ++i) { + auto ret = --count; - if (ret == 0) { - ++got0; - EXPECT_EQ(numIters - 1, i); - } + if (ret == 0) { + ++got0; + EXPECT_EQ(numIters - 1, i); } - }); + } + }); } for (size_t t = 0; t < numThreads; ++t) { diff --git a/folly/fibers/test/FibersTest.cpp b/folly/fibers/test/FibersTest.cpp index c193c7f5..c917eaa5 100644 --- a/folly/fibers/test/FibersTest.cpp +++ b/folly/fibers/test/FibersTest.cpp @@ -414,7 +414,7 @@ TEST(FiberManager, addTasksVoid) { manager.addTask([&]() { std::vector> funcs; for (size_t i = 0; i < 3; ++i) { - funcs.push_back([i, &pendingFibers]() { + funcs.push_back([&pendingFibers]() { await([&pendingFibers](Promise promise) { pendingFibers.push_back(std::move(promise)); }); @@ -679,7 +679,7 @@ TEST(FiberManager, collectNThrow) { manager.addTask([&]() { std::vector> funcs; for (size_t i = 0; i < 3; ++i) { - funcs.push_back([i, &pendingFibers]() -> size_t { + funcs.push_back([&pendingFibers]() -> size_t { await([&pendingFibers](Promise promise) { pendingFibers.push_back(std::move(promise)); }); @@ -718,7 +718,7 @@ TEST(FiberManager, collectNVoid) { manager.addTask([&]() { std::vector> funcs; for (size_t i = 0; i < 3; ++i) { - funcs.push_back([i, &pendingFibers]() { + funcs.push_back([&pendingFibers]() { await([&pendingFibers](Promise promise) { pendingFibers.push_back(std::move(promise)); }); @@ -754,7 +754,7 @@ TEST(FiberManager, collectNVoidThrow) { manager.addTask([&]() { std::vector> funcs; for (size_t i = 0; i < 3; ++i) { - funcs.push_back([i, &pendingFibers]() { + funcs.push_back([&pendingFibers]() { await([&pendingFibers](Promise promise) { pendingFibers.push_back(std::move(promise)); }); @@ -832,7 +832,7 @@ TEST(FiberManager, collectAllVoid) { manager.addTask([&]() { std::vector> funcs; for (size_t i = 0; i < 3; ++i) { - funcs.push_back([i, &pendingFibers]() { + funcs.push_back([&pendingFibers]() { await([&pendingFibers](Promise promise) { pendingFibers.push_back(std::move(promise)); }); @@ -1553,8 +1553,7 @@ TEST(FiberManager, semaphore) { int counterA = 0; int counterB = 0; - auto task = [&sem, kTasks, kIterations, kNumTokens]( - int& counter, folly::fibers::Baton& baton) { + auto task = [&sem, kNumTokens](int& counter, folly::fibers::Baton& baton) { FiberManager manager(std::make_unique()); folly::EventBase evb; dynamic_cast(manager.loopController()) @@ -1733,7 +1732,7 @@ TEST(FiberManager, doubleBatchDispatchTest) { template void batchDispatchExceptionHandling(ExecutorT& executor, int i) { thread_local BatchDispatcher batchDispatcher( - executor, [=, &executor](std::vector &&) -> std::vector { + executor, [](std::vector &&) -> std::vector { throw std::runtime_error("Surprise!!"); }); diff --git a/folly/futures/test/BarrierTest.cpp b/folly/futures/test/BarrierTest.cpp index 6a706793..b3419d14 100644 --- a/folly/futures/test/BarrierTest.cpp +++ b/folly/futures/test/BarrierTest.cpp @@ -137,23 +137,21 @@ TEST(BarrierTest, Random) { for (auto& tinfo : threads) { auto pinfo = &tinfo; - tinfo.thread = std::thread( - [numIterations, pinfo, &barrier] () { - std::vector> futures; - futures.reserve(pinfo->numFutures); - for (uint32_t i = 0; i < numIterations; ++i, ++pinfo->iteration) { - futures.clear(); - for (uint32_t j = 0; j < pinfo->numFutures; ++j) { - futures.push_back(barrier.wait()); - auto nanos = folly::Random::rand32(10 * 1000 * 1000); - /* sleep override */ - std::this_thread::sleep_for(std::chrono::nanoseconds(nanos)); - } - auto results = folly::collect(futures).get(); - pinfo->trueSeen[i] = - std::count(results.begin(), results.end(), true); - } - }); + tinfo.thread = std::thread([pinfo, &barrier] { + std::vector> futures; + futures.reserve(pinfo->numFutures); + for (uint32_t i = 0; i < numIterations; ++i, ++pinfo->iteration) { + futures.clear(); + for (uint32_t j = 0; j < pinfo->numFutures; ++j) { + futures.push_back(barrier.wait()); + auto nanos = folly::Random::rand32(10 * 1000 * 1000); + /* sleep override */ + std::this_thread::sleep_for(std::chrono::nanoseconds(nanos)); + } + auto results = folly::collect(futures).get(); + pinfo->trueSeen[i] = std::count(results.begin(), results.end(), true); + } + }); } for (auto& tinfo : threads) { diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 144a9249..3bfb8e33 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -618,7 +618,10 @@ TEST(Future, finishBigLambda) { EXPECT_EQ(bulk_data[0], 0); Promise p; - auto f = p.getFuture().then([x, bulk_data](Try&& t) { *x = t.value(); }); + auto f = p.getFuture().then([x, bulk_data](Try&& t) { + (void)bulk_data; + *x = t.value(); + }); // The callback hasn't executed EXPECT_EQ(0, *x); diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index 8a7f86c0..8819baa2 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -1809,7 +1809,7 @@ TEST(EventBaseTest, LoopKeepAliveWithLoopForever) { /* sleep override */ std::this_thread::sleep_for(std::chrono::milliseconds(30)); ASSERT_FALSE(done) << "Loop terminated early"; - ev->runInEventBaseThread([&ev, keepAlive = std::move(keepAlive) ]{}); + ev->runInEventBaseThread([keepAlive = std::move(keepAlive)]{}); } evThread.join(); diff --git a/folly/io/async/test/HHWheelTimerSlowTests.cpp b/folly/io/async/test/HHWheelTimerSlowTests.cpp index d1451c49..4fc1f083 100644 --- a/folly/io/async/test/HHWheelTimerSlowTests.cpp +++ b/folly/io/async/test/HHWheelTimerSlowTests.cpp @@ -307,7 +307,7 @@ TEST_F(HHWheelTimerTest, Stress) { runtimeouts++; /* sleep override */ usleep(1000); LOG(INFO) << "Ran " << runtimeouts << " timeouts of " << timeoutcount; - timeouts[i].fn = [&, i]() { + timeouts[i].fn = [&]() { runtimeouts++; LOG(INFO) << "Ran " << runtimeouts << " timeouts of " << timeoutcount; }; diff --git a/folly/io/test/CompressionTest.cpp b/folly/io/test/CompressionTest.cpp index 42296974..3036ba6d 100644 --- a/folly/io/test/CompressionTest.cpp +++ b/folly/io/test/CompressionTest.cpp @@ -91,15 +91,14 @@ RandomDataHolder::RandomDataHolder(size_t sizeLog2) std::vector threads; threads.reserve(numThreads); for (size_t t = 0; t < numThreads; ++t) { - threads.emplace_back( - [this, seed, t, numThreadsLog2, sizeLog2] () { - std::mt19937 rng(seed + t); - size_t countLog2 = sizeLog2 - numThreadsLog2; - size_t start = size_t(t) << countLog2; - for (size_t i = 0; i < countLog2; ++i) { - this->data_[start + i] = rng(); - } - }); + threads.emplace_back([this, seed, t, sizeLog2] { + std::mt19937 rng(seed + t); + size_t countLog2 = sizeLog2 - numThreadsLog2; + size_t start = size_t(t) << countLog2; + for (size_t i = 0; i < countLog2; ++i) { + this->data_[start + i] = rng(); + } + }); } for (auto& t : threads) { diff --git a/folly/test/AHMIntStressTest.cpp b/folly/test/AHMIntStressTest.cpp index f580a67f..e119cde9 100644 --- a/folly/test/AHMIntStressTest.cpp +++ b/folly/test/AHMIntStressTest.cpp @@ -108,17 +108,15 @@ TEST(AHMIntStressTest, Test) { std::vector threads; for (int threadId = 0; threadId < 64; ++threadId) { - threads.emplace_back( - [objs,threadId] { - for (int recycles = 0; recycles < 500; ++recycles) { - for (int i = 0; i < 10; i++) { - auto val = objs->get(i); - } - - objs->archive(); + threads.emplace_back([objs] { + for (int recycles = 0; recycles < 500; ++recycles) { + for (int i = 0; i < 10; i++) { + auto val = objs->get(i); } + + objs->archive(); } - ); + }); } for (auto& t : threads) t.join(); diff --git a/folly/test/AtomicLinkedListTest.cpp b/folly/test/AtomicLinkedListTest.cpp index 303261ff..97f4b160 100644 --- a/folly/test/AtomicLinkedListTest.cpp +++ b/folly/test/AtomicLinkedListTest.cpp @@ -133,12 +133,11 @@ TEST(AtomicIntrusiveLinkedList, Stress) { std::vector threads; for (size_t threadId = 0; threadId < kNumThreads; ++threadId) { - threads.emplace_back( - [threadId, kNumThreads, kNumElements, &list, &elements]() { - for (size_t id = 0; id < kNumElements; ++id) { - list.insertHead(&elements[threadId + kNumThreads * id]); - } - }); + threads.emplace_back([threadId, &list, &elements] { + for (size_t id = 0; id < kNumElements; ++id) { + list.insertHead(&elements[threadId + kNumThreads * id]); + } + }); } std::vector ids; diff --git a/folly/test/FunctionTest.cpp b/folly/test/FunctionTest.cpp index 042b3668..a7391009 100644 --- a/folly/test/FunctionTest.cpp +++ b/folly/test/FunctionTest.cpp @@ -322,7 +322,10 @@ TEST(Function, NonCopyableLambda) { (void)fooData; // suppress gcc warning about fooData not being used auto functor = std::bind( - [fooData](std::unique_ptr& up) mutable { return ++*up; }, + [fooData](std::unique_ptr& up) mutable { + (void)fooData; + return ++*up; + }, std::move(unique_ptr_int)); EXPECT_EQ(901, functor()); diff --git a/folly/test/MPMCPipelineTest.cpp b/folly/test/MPMCPipelineTest.cpp index b308c932..6c5b1b97 100644 --- a/folly/test/MPMCPipelineTest.cpp +++ b/folly/test/MPMCPipelineTest.cpp @@ -81,7 +81,7 @@ TEST(MPMCPipeline, MultiThreaded) { std::vector threads; threads.reserve(numThreadsPerStage * 2 + 1); for (size_t i = 0; i < numThreadsPerStage; ++i) { - threads.emplace_back([&a, i] () { + threads.emplace_back([&a] { for (;;) { int val; auto ticket = a.blockingReadStage<0>(val); @@ -97,7 +97,7 @@ TEST(MPMCPipeline, MultiThreaded) { } for (size_t i = 0; i < numThreadsPerStage; ++i) { - threads.emplace_back([&a, i] () { + threads.emplace_back([&a] { for (;;) { std::string val; auto ticket = a.blockingReadStage<1>(val); diff --git a/folly/test/SingletonThreadLocalTest.cpp b/folly/test/SingletonThreadLocalTest.cpp index f3e0ace0..43011471 100644 --- a/folly/test/SingletonThreadLocalTest.cpp +++ b/folly/test/SingletonThreadLocalTest.cpp @@ -44,14 +44,13 @@ TEST(SingletonThreadLocalTest, OneSingletonPerThread) { std::atomic completedThreadCount{0}; Synchronized> fooAddresses{}; std::vector threads{}; - auto threadFunction = - [&fooAddresses, targetThreadCount, &completedThreadCount] { - fooAddresses.wlock()->emplace(&FooSingletonTL::get()); - ++completedThreadCount; - while (completedThreadCount < targetThreadCount) { - std::this_thread::yield(); - } - }; + auto threadFunction = [&fooAddresses, &completedThreadCount] { + fooAddresses.wlock()->emplace(&FooSingletonTL::get()); + ++completedThreadCount; + while (completedThreadCount < targetThreadCount) { + std::this_thread::yield(); + } + }; { for (std::size_t threadCount{0}; threadCount < targetThreadCount; ++threadCount) { diff --git a/folly/test/SmallLocksBenchmark.cpp b/folly/test/SmallLocksBenchmark.cpp index b3568d06..28ecaeec 100644 --- a/folly/test/SmallLocksBenchmark.cpp +++ b/folly/test/SmallLocksBenchmark.cpp @@ -106,7 +106,7 @@ static void runContended(size_t numOps, size_t numThreads) { SimpleBarrier runbarrier(totalthreads + 1); for (size_t t = 0; t < totalthreads; ++t) { - threads[t] = std::thread([&, t, totalthreads] { + threads[t] = std::thread([&, t] { lockstruct* lock = &locks[t % threadgroups]; runbarrier.wait(); for (size_t op = 0; op < numOps; op += 1) { @@ -159,7 +159,7 @@ static void runFairness() { SimpleBarrier runbarrier(totalthreads + 1); for (size_t t = 0; t < totalthreads; ++t) { - threads[t] = std::thread([&, t, totalthreads] { + threads[t] = std::thread([&, t] { lockstruct* lock = &locks[t % threadgroups]; long value = 0; std::chrono::microseconds max(0); diff --git a/folly/test/ThreadLocalTest.cpp b/folly/test/ThreadLocalTest.cpp index 392a52fc..62526ebc 100644 --- a/folly/test/ThreadLocalTest.cpp +++ b/folly/test/ThreadLocalTest.cpp @@ -313,10 +313,12 @@ TEST(ThreadLocalPtr, AccessAllThreadsCounter) { std::atomic totalAtomic(0); std::vector threads; for (int i = 0; i < kNumThreads; ++i) { - threads.push_back(std::thread([&,i]() { + threads.push_back(std::thread([&]() { stci.add(1); totalAtomic.fetch_add(1); - while (run.load()) { usleep(100); } + while (run.load()) { + usleep(100); + } })); } while (totalAtomic.load() != kNumThreads) { usleep(100); } -- 2.34.1