From 88f09659e46497c353832aaa77f87dfb491702c2 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 16 Jul 2023 20:55:02 -0700 Subject: [PATCH] Workaround apparent g++12 spurious error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In file included from ../testshared.cpp:12: In constructor ‘pvxs::shared_array::shared_array(size_t, V) [with V = std::nullptr_t; E = std::unique_ptr; Enable = void]’, inlined from ‘void {anonymous}::testComplex()’ at ../testshared.cpp:225:57: ../../src/pvxs/sharedArray.h:288:17: error: pointer used after ‘void operator delete [](void*, std::size_t)’ [-Werror=use-after-free] 288 | :base_t(new _E_non_const[c], c) | ^~~~~~~~~~~~~~~~~~~ In member function ‘void pvxs::detail::sa_default_delete::operator()(E*) const [with E = std::unique_ptr]’, inlined from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter, _Alloc) [with _Ptr = std::unique_ptr*; _Deleter = pvxs::detail::sa_default_delete >; _Alloc = std::allocator; = void; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/12/bits/shared_ptr_base.h:958:11, inlined from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = std::unique_ptr*; _Deleter = pvxs::detail::sa_default_delete >; = void; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/12/bits/shared_ptr_base.h:939:57, inlined from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Yp*, _Deleter) [with _Yp = std::unique_ptr; _Deleter = pvxs::detail::sa_default_delete >; = void; _Tp = std::unique_ptr; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/12/bits/shared_ptr_base.h:1478:17, inlined from ‘std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter) [with _Yp = std::unique_ptr; _Deleter = pvxs::detail::sa_default_delete >; = void; _Tp = std::unique_ptr]’ at /usr/include/c++/12/bits/shared_ptr.h:232:48, inlined from ‘pvxs::detail::sa_base::sa_base(A*, size_t) [with A = std::unique_ptr; E = std::unique_ptr]’ at ../../src/pvxs/sharedArray.h:136:10, inlined from ‘pvxs::shared_array::shared_array(size_t, V) [with V = std::nullptr_t; E = std::unique_ptr; Enable = void]’ at ../../src/pvxs/sharedArray.h:288:39, inlined from ‘void {anonymous}::testComplex()’ at ../testshared.cpp:225:57: ../../src/pvxs/sharedArray.h:92:35: note: call to ‘void operator delete [](void*, std::size_t)’ here 92 | void operator()(E* e) const { delete[] e; } | ^~~~~~~~~~ --- test/testshared.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/testshared.cpp b/test/testshared.cpp index b9ebbd3..635acbb 100644 --- a/test/testshared.cpp +++ b/test/testshared.cpp @@ -218,14 +218,27 @@ void testFreezeThawVoid() testEq(C[0], 5u); } +struct ImMobile { + int v = 0; + ImMobile() = default; + + void store(int x) { v=x; } + int load() const { return v; } + + ImMobile(const ImMobile&) = delete; + ImMobile(ImMobile&&) = delete; + ImMobile& operator=(const ImMobile&) = delete; + ImMobile& operator=(ImMobile&&) = delete; +}; + void testComplex() { testDiag("%s", __func__); - shared_array> X(2, nullptr); + shared_array X(2); - X[0] = decltype (X)::value_type{new uint32_t(4u)}; - testEq(*X[0], 4u); + X[0].store(4); + testEq(X[0].load(), 4); } void testValue()