From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4531 invoked by alias); 17 May 2008 17:30:41 -0000 Received: (qmail 4522 invoked by uid 22791); 17 May 2008 17:30:40 -0000 X-Spam-Check-By: sourceware.org Received: from host287.ipowerweb.com (HELO host287.ipowerweb.com) (66.235.211.104) by sourceware.org (qpsmtpd/0.31) with SMTP; Sat, 17 May 2008 17:30:22 +0000 Received: (qmail 96787 invoked by uid 10022); 17 May 2008 17:30:20 -0000 Received: from 127.0.0.1 by host287.ipowerweb.com (envelope-from , uid 1002) with qmail-scanner-1.25st (clamdscan: 0.88/1245. spamassassin: 3.1.0. perlscan: 1.25st. Clear:RC:1(127.0.0.1):SA:0(-2.8/5.0):. Processed in 1.342151 secs); 17 May 2008 17:30:20 -0000 Received: from unknown (HELO host287.ipowerweb.com) (127.0.0.1) by host287.ipowerweb.com with SMTP; 17 May 2008 17:30:18 -0000 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 From: To: gcc-bugs@gcc.gnu.org Subject: sizeof() bug with gcc version 3.4.5 (mingw-vista special r3) Reply-To: yen-kwoon.hun@iugome.com X-Origin: 24.80.182.166 Date: Sat, 17 May 2008 17:30:00 -0000 X-Uidl: 1211045417967714545 X-Mailer: AtMail 4.03 X-Qmail-Scanner-Message-ID: <121104541892296778@host287.ipowerweb.com> Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-05/txt/msg01304.txt.bz2 Message-ID: <20080517173000.np3vyHKLovcJfbI0RpS24IpjusKENwdA03FSI1Eydb0@z> class base=0D {=0D public:=0D base(){};=0D ~base(){};=0D };=0D =0D class data : public base=0D {=0D public:=0D data(){};=0D ~data(){};=0D =0D private:=0D int member;=0D }__attribute__((__packed__));=0D =0D class group : public base=0D {=0D public:=0D group(){};=0D ~group(){};=0D =0D private:=0D data d1;=0D data d2;=0D data d3;=0D } __attribute__((__packed__));=0D =0D int main(int argc, char **argv)=0D {=0D std::cout << "base =3D " << sizeof(base) << std::endl;=0D std::cout << "data =3D " << sizeof(data) << std::endl;=0D std::cout << "group =3D " << sizeof(group) << std::endl;=0D return (0);=0D }=0D =0D =0D The output of the program is:=0D base =3D 1=0D data =3D 4=0D group =3D 13=0D =0D The result of sizeof(group) is puzzling as it should be 12 if EBO (empty ba= se=0D optimization) worked for both class data and group. Apparently EBO kicked i= n for=0D _ONLY_ one of them. If EBO didn't work at all, sizeof(group) should be 16.= =0D =0D Removing the extension of class base from either class group or data will c= ause=0D sizeof(group) to return 12. It seems that gcc is unable to fully apply EBO = when a=0D class and its member inherits the same empty base class.=0D =0D The same code had been tested on microsoft msvc compiler and realview arm=0D compiler, both correctly optimizes the code and give the correct value as 1= 2.=0D =0D Is this a known bug with gcc 3.4.5? I dug through the bugbase but couldn't = come=0D up with anything. Maybe EBO isn't the problem at all.=0D =0D Thanks!=0D =0D =0D =0D =0D