public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4181: mismatch in size of empty class
@ 2001-08-31  5:20 aoliva
  0 siblings, 0 replies; 2+ messages in thread
From: aoliva @ 2001-08-31  5:20 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, kirk, nobody

Synopsis: mismatch in size of empty class

State-Changed-From-To: open->closed
State-Changed-By: aoliva
State-Changed-When: Fri Aug 31 05:20:29 2001
State-Changed-Why:
    Not a bug.  Padding is required to maintain alignment.  GCC 3.0 optimizes empty base classes away entirely, so you'll see the size of the class is 4, not 8 or 5.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4181&database=gcc


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/4181: mismatch in size of empty class
@ 2001-08-30 13:46 kirk
  0 siblings, 0 replies; 2+ messages in thread
From: kirk @ 2001-08-30 13:46 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4181
>Category:       c++
>Synopsis:       mismatch in size of empty class
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 30 13:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     kirk@kaybee.org
>Release:        2.96 20000731
>Organization:
>Environment:
Red Hat Linux 7.1
>Description:
The size of an empty class is given to be 1 byte.
However, an object derived from the empty class that contains
a 4-byte variable, has a reported size of 8 bytes.

This disparity in object sizes might be a bug in itself.
However, I noticed one severe problem as a result of this problem.
Looking at a running program, I found that 8 bytes of memory
is indeed allocated for the object.  However, I had a perfectly 
valid line of code that accessed a member of the derived
class, but it counted the empty base class (located first
in the memory allocated for the derived object) as 1 byte,
therefore accessing 3 bytes earlier in memory than it should
have, and returning corrupt memory.

Unfortunately, I tried to make a program that simulates 
the exact problem as it occurred, but I can't get it to
happen.  Unfortunately, the original program is much
too big and complicated to submit here.
>How-To-Repeat:
Unfortunately, I tried to make a program that simulates 
the exact problem as it occurred, but I can't get it to
happen.  Unfortunately, the original program is much
too big and complicated to submit here.

However, I hope that the information I provided and
the attached code will help you track down the problem.

Somewhere in gcc, it assumed in one place that the empty object was
only one byte when 4 bytes was actually allocated.  This was
when accessing a data element from a pointer to the derived
object, such as obj->member.  
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test2.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test2.cpp"

I2luY2x1ZGUgPHN0ZGlvLmg+CgpjbGFzcyBEdW1teSB7Cn07CgpjbGFzcyBUZXN0T2JqIDogcHVi
bGljIER1bW15IHsKICAgIHB1YmxpYzoKICAgICAgICBpbnQqIHB0cjsKCn07CgppbnQgbWFpbiAo
dm9pZCkgewogICAgVGVzdE9iaiogdGVzdDsKICAgIGludCB4OwogICAgdGVzdC0+cHRyID0gJng7
CiAgICBwcmludGYgKCJBY3R1YWwgYWRkcmVzcyBvZiB4OiAlcFxuIiwgJngpOwogICAgcHJpbnRm
ICgiUmV0dXJuZWQgYWRkcmVzcyBvZiB4OiAlcFxuIiwgdGVzdC0+cHRyKTsKICAgIHByaW50ZiAo
InNpemVvZihEdW1teSk6ICVkXG4iLCBzaXplb2YoRHVtbXkpKTsKICAgIHByaW50ZiAoInNpemVv
ZihUZXN0T2JqKTogJWRcbiIsIHNpemVvZihUZXN0T2JqKSk7CiAgICByZXR1cm4gMDsKfQoK


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-31  5:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-31  5:20 c++/4181: mismatch in size of empty class aoliva
  -- strict thread matches above, loose matches on Subject: below --
2001-08-30 13:46 kirk

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).