From fd1c1dd658221dcccbaeeac5c6ae644fab274019 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Thu, 8 Jun 2023 12:25:32 +0000 Subject: [PATCH 1/3] stl_alloc-t.cc: fixed compilation error with GCC 13 In file included from /usr/include/c++/13/ext/alloc_traits.h:34, from /usr/include/c++/13/bits/stl_uninitialized.h:64, from /usr/include/c++/13/memory:69, from /usr/src/RPM/BUILD/MySQL-8.0.30/extra/googletest/googletest-release-1.11.0/googletest/include/gtest/gtest.h:57, from /usr/src/RPM/BUILD/MySQL-8.0.30/unittest/gunit/stl_alloc-t.cc:23: /usr/include/c++/13/bits/alloc_traits.h: In instantiation of 'struct std::__allocator_traits_base::__rebind >, std::unique_ptr, void>': /usr/include/c++/13/bits/alloc_traits.h:94:11: required by substitution of 'template using std::__alloc_rebind = typename std::__allocator_traits_base::__rebind<_Alloc, _Up>::type [with _Alloc = stlalloc_unittest::Mem_root_allocator_wrapper >; _Up = std::unique_ptr]' /usr/include/c++/13/bits/alloc_traits.h:228:8: required by substitution of 'template template using std::allocator_traits< >::rebind_alloc = std::__alloc_rebind<_Alloc, _Tp> [with _Tp = std::unique_ptr; _Alloc = stlalloc_unittest::Mem_root_allocator_wrapper >]' /usr/include/c++/13/ext/alloc_traits.h:126:65: required from 'struct __gnu_cxx::__alloc_traits >, std::unique_ptr >::rebind >' /usr/include/c++/13/bits/stl_vector.h:88:21: required from 'struct std::_Vector_base, stlalloc_unittest::Mem_root_allocator_wrapper > >' /usr/include/c++/13/bits/stl_vector.h:423:11: required from 'class std::vector, stlalloc_unittest::Mem_root_allocator_wrapper > >' /usr/src/RPM/BUILD/MySQL-8.0.30/unittest/gunit/stl_alloc-t.cc:406:43: required from 'void stlalloc_unittest::STLAllocTestMoveOnly_MoveOnly_Test::TestBody() [with gtest_TypeParam_ = stlalloc_unittest::Mem_root_allocator_wrapper >]' /usr/src/RPM/BUILD/MySQL-8.0.30/unittest/gunit/stl_alloc-t.cc:405:1: required from here /usr/include/c++/13/bits/alloc_traits.h:70:31: error: static assertion failed: allocator_traits::rebind_alloc must be A 70 | _Tp>::value, | ^~~~~ /usr/include/c++/13/bits/alloc_traits.h:70:31: note: 'std::integral_constant::value' evaluates to false To avoid the failure properly override `rebind` in Mem_root_allocator_wrapper and implement conversion constructors (same for Malloc_allocator_wrapper). --- unittest/gunit/stl_alloc-t.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/unittest/gunit/stl_alloc-t.cc b/unittest/gunit/stl_alloc-t.cc index 08316235409..fb1ce07ddd0 100644 --- a/unittest/gunit/stl_alloc-t.cc +++ b/unittest/gunit/stl_alloc-t.cc @@ -57,6 +57,14 @@ template class Malloc_allocator_wrapper : public Malloc_allocator { public: Malloc_allocator_wrapper() : Malloc_allocator(PSI_NOT_INSTRUMENTED) {} + + template + Malloc_allocator_wrapper(const Malloc_allocator_wrapper &other [[maybe_unused]]) + : Malloc_allocator(PSI_NOT_INSTRUMENTED) {} + template + struct rebind { + typedef Malloc_allocator_wrapper other; + }; }; template @@ -69,6 +77,12 @@ class Mem_root_allocator_wrapper : public Mem_root_allocator { m_mem_root.set_error_handler(nullptr); } + template + Mem_root_allocator_wrapper(const Mem_root_allocator_wrapper &other [[maybe_unused]]) + : Mem_root_allocator(&m_mem_root) { + m_mem_root.set_error_handler(nullptr); + } + /* Allocators before C++17 need to be copy-constructible, and libc++ enforces this (libstdc++ is fine with them being move-only). As a hack, we implement @@ -82,6 +96,11 @@ class Mem_root_allocator_wrapper : public Mem_root_allocator { : Mem_root_allocator(&m_mem_root) { memcpy(&m_mem_root, &other.m_mem_root, sizeof(m_mem_root)); } + + template + struct rebind { + typedef Mem_root_allocator_wrapper other; + }; }; /* -- 2.33.3