From 3888ebcfbac5eabf2b4c0ea17bbbbaa3808d1364 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 19 Sep 2024 21:26:36 +0800 Subject: [PATCH] build: check for P2582R1 support in a recent GCC packaging update in fedora, the maintainer backported a patch [PR116276](https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659909.html) from GCC-14. the patch implements [P2582R1 - Wording for class template argument deduction from inherited constructors](https://wg21.link/P2582R1) which was accepted by C++23. since it's included by C++23, Clang is also working in this direction, see https://github.com/llvm/llvm-project/issues/92606. this is the reason why gcc-14.2.1-3 fails to build the tree, which relies on the behavior without P2582R1. in this change, we check for the support of P2581R1 with CMake, and defined `SEASTAR_P2581R1` macro if the proposed behavior is implemented. we define the argument deduction guide for `rpc::tuple` only if this macro is not defined. this should address the build failure. and it is future-proof as once Clang supports P2581R1, we can detect it, and disable the dedution guide as well. Fixes #2445 Signed-off-by: Kefu Chai --- CMakeLists.txt | 8 ++++++++ cmake/CheckP2582R1.cmake | 26 ++++++++++++++++++++++++++ include/seastar/rpc/rpc_types.hh | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 cmake/CheckP2582R1.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 68359341d58..7e1bb64d189 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -821,6 +821,14 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -Wno-error=deprecated-declarations) endif () +if (CMAKE_CXX_STANDARD GREATER_EQUAL 23) + include (CheckP2582R1) + if (Cxx_Compiler_IMPLEMENTS_P2581R1) + target_compile_definitions (seastar + PUBLIC SEASTAR_P2581R1) + endif () +endif () + if (BUILD_SHARED_LIBS) # use initial-exec TLS, as it puts the TLS variables in the static TLS space # instead of allocating them using malloc. otherwise intercepting mallocs and diff --git a/cmake/CheckP2582R1.cmake b/cmake/CheckP2582R1.cmake new file mode 100644 index 00000000000..731e8f67d67 --- /dev/null +++ b/cmake/CheckP2582R1.cmake @@ -0,0 +1,26 @@ +include (CheckCXXSourceCompiles) +include (CMakePushCheckState) + +cmake_push_check_state (RESET) + +set (CMAKE_REQUIRED_FLAGS "-std=c++23") + +# check if the compiler implements the inherited vs non-inherited guide +# tiebreaker specified by P2582R1, see https://wg21.link/P2582R1 +check_cxx_source_compiles (" +template struct B { + B(T) {} +}; + +template struct C : public B { + using B::B; +}; + +B(int) -> B; +C c2(42); + +int main() {} +" + Cxx_Compiler_IMPLEMENTS_P2581R1) + +cmake_pop_check_state () diff --git a/include/seastar/rpc/rpc_types.hh b/include/seastar/rpc/rpc_types.hh index 8c6270119ec..c66a90e85f9 100644 --- a/include/seastar/rpc/rpc_types.hh +++ b/include/seastar/rpc/rpc_types.hh @@ -403,8 +403,10 @@ public: /// @} +#ifndef SEASTAR_P2581R1 template tuple(T&&...) -> tuple; +#endif } // namespace rpc