Почему я получаю ошибку компиляции class-memaccess с boost :: atomic_shared_ptr? - PullRequest
0 голосов
/ 12 июня 2018

Пример кода, приводящего к ошибке: (https://godbolt.org/g/WWkTHr):

#include <boost/smart_ptr/atomic_shared_ptr.hpp>
#include <boost/make_shared.hpp>

int main() {
    boost::shared_ptr<int> tmp = boost::make_shared<int>();
    boost::atomic_shared_ptr<int> test(tmp);
}

Ошибка компиляции с GCC 8.1 с -Werror = class-memaccess:

In file included from <source>:1:
/opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/atomic_shared_ptr.hpp: In instantiation of 'boost::atomic_shared_ptr<T>::atomic_shared_ptr(boost::shared_ptr<X>) [with T = int]':
<source>:6:43:   required from here
/opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/atomic_shared_ptr.hpp:84:20: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class boost::detail::spinlock' with no trivial copy-assignment [-Werror=class-memaccess]
         std::memcpy( &l_, &init, sizeof( init ) );
         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/detail/spinlock.hpp:47,
                 from /opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/detail/spinlock_pool.hpp:25,
                 from /opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/shared_ptr.hpp:36,
                 from /opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/atomic_shared_ptr.hpp:16,
                 from <source>:1:
/opt/compiler-explorer/libs/boost_1_67_0/boost/smart_ptr/detail/spinlock_std_atomic.hpp:27:7: note: 'class boost::detail::spinlock' declared here
 class spinlock
       ^~~~~~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1
...