Opened 7 years ago
Closed 7 years ago
#11286 closed Bugs (invalid)
Code in boost/endian/buffers.hpp violates old C++03 Standard
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | endian |
Version: | Boost 1.58.0 | Severity: | Problem |
Keywords: | Cc: | Aparna.Kumta@… |
Description
- Description of the failure.
- endian/test/endian_in_union_test.cc fails with Oracle Studio C++ compiler on Solaris producing bunch of similar error message similar shown below
"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"
"endian_in_union_test.cpp", line 77: Error: A union member cannot have a user-defined assignment operator.
- Cause of the failure.
The failure can be demonstrated with 4 lines small independent t.cpp test:
class endian_buffer {
endian &endian_buffer = (int val);
};
union U { endian_buffer m; };
CC -c t.cpp
"t.cc", line 4: Error: A union member cannot have a user-defined assignment operator.
Small test above has been extracted and slightly modified from the code shown below located under boost/endian/buffers.hpp
template <typename T, std::size_t n_bits>
class endian_buffer< order::big, T, n_bits, align::no >
{
....
endian_buffer & operator=(T val) BOOST_NOEXCEPT Line 358
C++03 Standard explicitly rejects the use of classes with user-defined assignment operators in unions:
C++2003 9.5 [class.union]p1
An object of a class with a ... non-trivial copy assignment operator (13.5.3, 12.8) cannot be a member of a union.
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.
Seems like g++ has a bug here compiling this code successfully in both C++03 and C++11 mode.
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is not a bug in endian_in_union_test.cpp.
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.
The test passes for modern gcc, clang, and msvc compilers in -std=c++03 mode.
--Beman
After filing this ticket I realized that I was not quite right about header itself.
Actually boost/endian/buffers.hpp code is good, because it only contains
endian_buffer & operator=(T val)
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?