public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54258] New: Wrong size of a named union.
@ 2012-08-14 16:25 karolmdv at gazeta dot pl
2012-08-14 16:38 ` [Bug c++/54258] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: karolmdv at gazeta dot pl @ 2012-08-14 16:25 UTC (permalink / raw)
To: gcc-bugs
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: unassigned@gcc.gnu.org
ReportedBy: karolmdv@gazeta.pl
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/54258] Wrong size of a named union.
2012-08-14 16:25 [Bug c++/54258] New: Wrong size of a named union karolmdv at gazeta dot pl
@ 2012-08-14 16:38 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2012-08-14 16:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54258
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-14 16:38:32 UTC ---
my_aligned_storage is an empty type, i.e. has no members, so has size 1.
my_aligned_storage::type is not a member, it's a declaration of a type.
If you remove the name 'type' then the anon union is a member, not a type
declaration.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-14 16:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-14 16:25 [Bug c++/54258] New: Wrong size of a named union karolmdv at gazeta dot pl
2012-08-14 16:38 ` [Bug c++/54258] " redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).