public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: <yen-kwoon.hun@iugome.com> To: gcc-bugs@gcc.gnu.org Subject: sizeof() bug with gcc version 3.4.5 (mingw-vista special r3) Date: Sat, 17 May 2008 17:30:00 -0000 [thread overview] Message-ID: <20080517173000.np3vyHKLovcJfbI0RpS24IpjusKENwdA03FSI1Eydb0@z> (raw) 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!
reply other threads:[~2008-05-17 17:30 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080517173000.np3vyHKLovcJfbI0RpS24IpjusKENwdA03FSI1Eydb0@z \ --to=yen-kwoon.hun@iugome.com \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).