This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
FW: sizeof() issue on gcc version 3.4.5
- From: "Yen-Kwoon Hun" <yen-kwoon dot hun at iugome dot com>
- To: <gcc-bugs at gcc dot gnu dot org>
- Date: Tue, 20 May 2008 11:49:03 -0700
- Subject: FW: sizeof() issue on gcc version 3.4.5
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? (Note: I'm using MinGW) I dug through
the bugbase but couldn't come
up with anything. Maybe EBO isn't the problem at all.
Thanks!