From 60b7dc2f52091d8e17a3baee51941c1db8ef6fc5 Mon Sep 17 00:00:00 2001 From: Lucas Czech Date: Mon, 9 Dec 2024 12:00:41 +0100 Subject: [PATCH] Fix some compiler issues --- lib/genesis/utils/threading/thread_pool.hpp | 29 +++++++++++-------- .../threading/concurrent_vector_guard.cpp | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/genesis/utils/threading/thread_pool.hpp b/lib/genesis/utils/threading/thread_pool.hpp index 0589005f..3ec91f8c 100644 --- a/lib/genesis/utils/threading/thread_pool.hpp +++ b/lib/genesis/utils/threading/thread_pool.hpp @@ -702,24 +702,29 @@ class ThreadPool inline auto make_task_function_( F&& f, Args&&... args ) -> std::function::type ()> { - // Unfortunately, Clang 18 uses std::result_of within std::bind, which is however deprecated, + // Unfortunately, Clang 18 when compiled under the C++20 standard somehow uses + // std::result_of within std::bind, despite that being deprecated in the standard, // and hence leads to a warning, and as we set warnings as errors, fails to compile. // See https://gcc.gnu.org/pipermail/libstdc++/2024-March/058502.html for details. // This is the reason why we internally use genesis_invoke_result instead, to switch - // between the two. But doesn't work of course for the STL... So we need to silence this. + // between the two. But doesn't work of course for the STL... + // So we need a workaround for this. Silencing via #pragma diagnostic does not seem + // to work, so instead, we just completely get rid of the std::bind for C++ standards + // that support variadic lambda captures. // This is the whole reason for this function. Super ugly, but it is what it is. - #if defined(__clang__) && (__clang_major__ == 18) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - #pragma clang diagnostic ignored "-Wpedantic" - #endif + #if GENESIS_CPP_STD >= GENESIS_CPP_STD_17 + + // Use a modern way to bind the args to the function. + return [f = std::forward(f), ...args = std::forward(args)]() mutable + { + return f(args...); + }; + + #else - // Make the function via binding. - return std::bind( std::forward(f), std::forward(args)... ); + // Make the function via binding. + return std::bind( std::forward(f), std::forward(args)... ); - // Undo the silencing. - #if defined(__clang__) && (__clang_major__ == 18) - #pragma clang diagnostic pop #endif } diff --git a/test/src/utils/threading/concurrent_vector_guard.cpp b/test/src/utils/threading/concurrent_vector_guard.cpp index f4449840..69e22e28 100644 --- a/test/src/utils/threading/concurrent_vector_guard.cpp +++ b/test/src/utils/threading/concurrent_vector_guard.cpp @@ -117,7 +117,7 @@ TEST( Threading, VectorEntries ) // them from their vec within data, until empty, and then moves to the next one. auto thread_pool = std::make_shared( num_threads ); auto vector_guard = ConcurrentVectorGuard( num_vecs ); - std::atomic num_elem = 0; + auto num_elem = std::atomic{0}; for( size_t t = 0; t < num_threads; ++t ) { thread_pool->enqueue_detached([&, t]() {