public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* sizeof() bug with gcc version 3.4.5 (mingw-vista special r3)
@ 2008-05-17 17:30 yen-kwoon.hun
  0 siblings, 0 replies; only message in thread
From: yen-kwoon.hun @ 2008-05-17 17:30 UTC (permalink / raw)
  To: gcc-bugs

class base
{
public:
base(){};
~base(){};
};

class data : public base
{
public:
data(){};
~data(){};

private:
int member;
}__attribute__((__packed__));

class group : public base
{
public:
group(){};
~group(){};

private:
data d1;
data d2;
data d3;
} __attribute__((__packed__));

int main(int argc, char **argv)
{
std::cout << "base = " << sizeof(base) << std::endl;
std::cout << "data = " << sizeof(data) << std::endl;
std::cout << "group = " << sizeof(group) << std::endl;
return (0);
}


The output of the program is:
base = 1
data = 4
group = 13

The result of sizeof(group) is puzzling as it should be 12 if EBO (empty base
optimization) worked for both class data and group. Apparently EBO kicked in for
_ONLY_ one of them. If EBO didn't work at all, sizeof(group) should be 16.

Removing the extension of class base from either class group or data will cause
sizeof(group) to return 12. It seems that gcc is unable to fully apply EBO when a
class and its member inherits the same empty base class.

The same code had been tested on microsoft msvc compiler and realview arm
compiler, both correctly optimizes the code and give the correct value as 12.

Is this a known bug with gcc 3.4.5? I dug through the bugbase but couldn't come
up with anything. Maybe EBO isn't the problem at all.

Thanks!






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-17 17:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-17 17:30 sizeof() bug with gcc version 3.4.5 (mingw-vista special r3) yen-kwoon.hun

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