Opened 6 years ago
Closed 5 years ago
#12940 closed Bugs (fixed)
Missing initializer for member
Reported by: | Owned by: | timblechmann | |
---|---|---|---|
Milestone: | To Be Determined | Component: | atomic |
Version: | Boost 1.63.0 | Severity: | Problem |
Keywords: | Cc: | Andrey.Semashev@… |
Description
I have the following error when compiling with my built boost 1.63:
/usr/include/boost/atomic/detail/bitwise_cast.hpp: In instantiation of 'To boost::atomics::detail::bitwise_cast(const From&) [with To = long unsigned int; From = void*]': /usr/include/boost/atomic/detail/atomic_template.hpp:556:139: required from here /usr/include/boost/atomic/detail/bitwise_cast.hpp:39:14: error: missing initializer for member 'boost::atomics::detail::bitwise_cast(const From&) [with To = long unsigned int; From = void*]::<anonymous struct>::to' [-Werror=missing-field-initializers] value = {};
The code looks like:
template< typename To, typename From > BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT { struct { To to; } value = {}; BOOST_ATOMIC_DETAIL_MEMCPY ( &reinterpret_cast< char& >(value.to), &reinterpret_cast< const char& >(from), (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To)) ); return value.to; }
My proposed fix is:
template< typename To, typename From > BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT { struct Value { To to; Value() : to() {} } struct Value value; BOOST_ATOMIC_DETAIL_MEMCPY ( &reinterpret_cast< char& >(value.to), &reinterpret_cast< const char& >(from), (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To)) ); return value.to; }
Attachments (1)
Change History (2)
by , 6 years ago
Attachment: | 0002-Avoid-missing-field-initializzer-warning.patch added |
---|
comment:1 by , 5 years ago
Cc: | added |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Not all compilers support value initialization properly, so the proposed solution is not quite portable.
The warning should be fixed in https://github.com/boostorg/atomic/commit/078639812015b96f64eb88a67a857d12201aab17.
Note:
See TracTickets
for help on using tickets.
Proposed git format-patch for downloaded source