public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/8956: Class layout: exessive padding for simple inheritance case
@ 2002-12-16 0:06 johnb
0 siblings, 0 replies; 2+ messages in thread
From: johnb @ 2002-12-16 0:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 8956
>Category: c++
>Synopsis: Class layout: exessive padding for simple inheritance case
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Dec 16 00:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Eugeny Belov
>Release: g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7), g++ (GCC) 3.2 on UnitedLinux 1.0 (ia64)
>Organization:
>Environment:
Red Hat Linux 8.0 on IA32
United Linux 1.0 on IA64
>Description:
I found only the similar report #8684 in the bugs database, but not the same. I can reproduce the failure on both IA32 and IA64 plattforms with g++ 3.2.
Here is the testcase:
#include <iostream>
struct S {
int i;
short s;
};
struct T : public S {
short t;
};
struct U {
int i;
short s;
short t;
};
int main (void)
{
if (sizeof (T) == sizeof (U))
std::cout << "PASSED\n";
else
std::cout << "FAILED " << sizeof(T) << "!=" << sizeof (U) << std::endl;
return 0;
}
According to the C++ ABI (http://www.codesourcery.com/cxx-abi/abi.html) it is expected that layout of T should be the same as layout of U and have the same size.
What is happening when we start to laying out the T - we have to put at the beginning the base class S, then we should place the T`s short element and finish the layout. But the trick is that T`s short element should be placed at offset dsize(S) (sizeof(S) without tail padding - padding is presented in S after short type element). It seems that g++ put the T`s short member at offset sizeof(S) and it is wrong.
>How-To-Repeat:
Compile testcase with g++ v3.2 and run, You`ll see the FAILED message.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="tfields4.cpp"
Content-Disposition: inline; filename="tfields4.cpp"
#include <iostream>
struct S {
int i;
short s;
};
struct T : public S {
short t;
};
struct U {
int i;
short s;
short t;
};
int main (void)
{
if (sizeof (T) == sizeof (U))
std::cout << "PASSED\n";
else
std::cout << "FAILED " << sizeof(T) << "!=" << sizeof (U) << std::endl;
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/8956: Class layout: exessive padding for simple inheritance case
@ 2002-12-16 1:27 nathan
0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-12-16 1:27 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, johnb, nobody
Synopsis: Class layout: exessive padding for simple inheritance case
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Mon Dec 16 01:27:49 2002
State-Changed-Why:
not a bug. S is a POD class, and its tail padding cannot be
used. See 2.2 of the ABI doc
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8956
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-12-16 9:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-16 0:06 c++/8956: Class layout: exessive padding for simple inheritance case johnb
2002-12-16 1:27 nathan
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).