Boost C++ Libraries: Ticket #12940: Missing initializer for member https://svn.boost.org/trac10/ticket/12940 <p> I have the following error when compiling with my built boost 1.63: </p> <pre class="wiki">/usr/include/boost/atomic/detail/bitwise_cast.hpp: In instantiation of 'To boost::atomics::detail::bitwise_cast(const From&amp;) [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&amp;) [with To = long unsigned int; From = void*]::&lt;anonymous struct&gt;::to' [-Werror=missing-field-initializers] value = {}; </pre><p> The code looks like: </p> <pre class="wiki">template&lt; typename To, typename From &gt; BOOST_FORCEINLINE To bitwise_cast(From const&amp; from) BOOST_NOEXCEPT { struct { To to; } value = {}; BOOST_ATOMIC_DETAIL_MEMCPY ( &amp;reinterpret_cast&lt; char&amp; &gt;(value.to), &amp;reinterpret_cast&lt; const char&amp; &gt;(from), (sizeof(From) &lt; sizeof(To) ? sizeof(From) : sizeof(To)) ); return value.to; } </pre><p> My proposed fix is: </p> <pre class="wiki">template&lt; typename To, typename From &gt; BOOST_FORCEINLINE To bitwise_cast(From const&amp; from) BOOST_NOEXCEPT { struct Value { To to; Value() : to() {} } struct Value value; BOOST_ATOMIC_DETAIL_MEMCPY ( &amp;reinterpret_cast&lt; char&amp; &gt;(value.to), &amp;reinterpret_cast&lt; const char&amp; &gt;(from), (sizeof(From) &lt; sizeof(To) ? sizeof(From) : sizeof(To)) ); return value.to; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12940 Trac 1.4.3 mattyclarkson@… Thu, 30 Mar 2017 09:57:55 GMT attachment set https://svn.boost.org/trac10/ticket/12940 https://svn.boost.org/trac10/ticket/12940 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">0002-Avoid-missing-field-initializzer-warning.patch</span> </li> </ul> <p> Proposed git format-patch for downloaded source </p> Ticket Andrey Semashev Tue, 30 May 2017 10:33:19 GMT status changed; cc, resolution set https://svn.boost.org/trac10/ticket/12940#comment:1 https://svn.boost.org/trac10/ticket/12940#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">Andrey.Semashev@…</span> added </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Not all compilers support value initialization properly, so the proposed solution is not quite portable. </p> <p> The warning should be fixed in <a class="ext-link" href="https://github.com/boostorg/atomic/commit/078639812015b96f64eb88a67a857d12201aab17"><span class="icon">​</span>https://github.com/boostorg/atomic/commit/078639812015b96f64eb88a67a857d12201aab17</a>. </p> Ticket