Reduce compiler warnings when boost uses std-atomics
authorRobin Gareus <robin@gareus.org>
Sun, 28 Jul 2019 18:10:09 +0000 (20:10 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 28 Jul 2019 18:10:09 +0000 (20:10 +0200)
This works around for compilers with non-static-data-member
initialization.

spinlock_t is-a struct { lockType _; } and BOOST_DETAIL_SPINLOCK_INIT
initializes the first member of the struct.
All defines of BOOST_DETAIL_SPINLOCK_INIT include c-style curly braces
to initialize the struct's data member.

However, modern C++ compiler interpret the braces differently resulting
in copy constriction of the initializer.

libs/pbd/spinlock.cc

index 45e35daf370a458a8f33d06c96e7c7ee0f7dd62d..0e53b194b9a05a4a58af684b094648eb3f50a5be 100644 (file)
 using namespace PBD;
 
 spinlock_t::spinlock_t ()
+#ifdef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
+       /* C++11 non-static data member initialization,
+        * with non-copyable std::atomic ATOMIC_FLAG_INIT
+        */
+       : l {BOOST_DETAIL_SPINLOCK_INIT} {}
+#else
+       /* default C++ assign struct's first member */
 {
-       boost::detail::spinlock init = BOOST_DETAIL_SPINLOCK_INIT;
-       std::memcpy (&l, &init, sizeof (init));
+       l = BOOST_DETAIL_SPINLOCK_INIT;
 }
+#endif
 
 SpinLock::SpinLock (spinlock_t& lock)
        : _lock (lock)