http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54258
Bug #: 54258
Summary: Wrong size of a named union.
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Created attachment 28014
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28014
Compiler's output.
I tried to find it in the current list of open bugs and have seen many similar
union-specific ones.
The problem was detected when using std::aligned_storage, when noticed that
sizeof(std::aligned_storage<x>) yields 1 for any "x".
The following code demonstrates the problem.
----------------------------------------------------------------
int main()
{
// If "type" is removed (making the union anonymous),
// it works and returns 18.
struct my_aligned_storage
{
union type
{
unsigned char __data[18];
};
};
return sizeof(my_aligned_storage); // Returns 1.
}
----------------------------------------------------------------
It has been compiled with (GCC 4.7.0):
g++ -v -save-temps -o bug.exe -std=gnu++11 bug.cpp
Full compiler's output is in the attachment.