Boost C++ Libraries: Ticket #11286: Code in boost/endian/buffers.hpp violates old C++03 Standard https://svn.boost.org/trac10/ticket/11286 <ol><li>Description of the failure. </li></ol><dl class="wiki"><dt>endian/test/endian_in_union_test.cc fails with Oracle Studio C++ compiler on Solaris producing bunch of similar error message similar shown below</dt><dd> </dd></dl> <blockquote> <p> "CC" -KPIC -DBOOST_ALL_NO_LIB=1 -DNDEBUG -I"../../.." -o "../../../bin.v2/libs/endian/test/endian_in_union_test.test/sun/release/stdlib-sun-stlport/threading-multi/endian_in_union_test.o" "endian_in_union_test.cpp" </p> </blockquote> <p> "endian_in_union_test.cpp", line 77: Error: A union member cannot have a user-defined assignment operator. </p> <ol start="2"><li>Cause of the failure. </li></ol><blockquote> <p> The failure can be demonstrated with 4 lines small independent t.cpp test: </p> </blockquote> <blockquote> <blockquote> <p> class endian_buffer { </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> endian &amp;endian_buffer = (int val); </p> </blockquote> <p> }; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> union U { endian_buffer m; }; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> CC -c t.cpp </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> "t.cc", line 4: Error: A union member cannot have a user-defined assignment operator. </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> Small test above has been extracted and slightly modified from the code shown below located under boost/endian/buffers.hpp </p> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> template &lt;typename T, std::size_t n_bits&gt; </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> class endian_buffer&lt; order::big, T, n_bits, align::no &gt; </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> { </p> <blockquote> <p> .... </p> </blockquote> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p> endian_buffer &amp; operator=(T val) BOOST_NOEXCEPT <em> Line 358 </em></p> </blockquote> </blockquote> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <blockquote> <p> C++03 Standard explicitly rejects the use of classes with user-defined assignment operators in unions: </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> C++2003 9.5 [class.union]p1 </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> An object of a class with a ... non-trivial copy assignment operator (13.5.3, 12.8) cannot be a member of a union. </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p> In C++11 the code is valid, as a result of apply "Unrestricted Unions" feature. But since it is a C++11 feature, it should not affect C++03 compilation. </p> </blockquote> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <blockquote> <p> Seems like g++ has a bug here compiling this code successfully in both C++03 and C++11 mode. </p> </blockquote> </blockquote> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11286 Trac 1.4.3 Sergey.Sprogis@… Mon, 11 May 2015 21:33:15 GMT <link>https://svn.boost.org/trac10/ticket/11286#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11286#comment:1</guid> <description> <p> After filing this ticket I realized that I was not quite right about header itself. </p> <p> Actually boost/endian/buffers.hpp code is good, because it only contains </p> <p> endian_buffer &amp; operator=(T val) </p> <p> but the real issue is inside libs/endian/test/endian_in_union_test.cpp test itself which contains 'union U' Based on this, the fix should be pretty easy: just to put all those unions under some NO_CXX11 macro. Only I'm not sure which one is currently most suitable for that kind of differences. May be a new one should created? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Mon, 27 Jul 2015 14:13:09 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11286#comment:2 https://svn.boost.org/trac10/ticket/11286#comment:2 <ul> <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">invalid</span> </li> </ul> <p> This is not a bug in endian_in_union_test.cpp. </p> <p> This is a error caused by a bug in an older version of the compiler. It confused user-defined assignment with user-defined copy assignment, which is what is actually prohibited. This was a bug in some older versions of GCC that has since been fixed. </p> <p> The test passes for modern gcc, clang, and msvc compilers in -std=c++03 mode. </p> <p> --Beman </p> Ticket