From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11824 invoked by alias); 3 Jul 2002 18:06:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 11788 invoked by uid 71); 3 Jul 2002 18:06:01 -0000 Resent-Date: 3 Jul 2002 18:06:01 -0000 Resent-Message-ID: <20020703180601.11787.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, markus@noga.de Received: (qmail 10636 invoked by uid 61); 3 Jul 2002 18:04:29 -0000 Message-Id: <20020703180429.10635.qmail@sources.redhat.com> Date: Wed, 03 Jul 2002 11:06:00 -0000 From: markus@noga.de Reply-To: markus@noga.de To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/7201: Multiple inheritance from classes without data members wastes memory X-SW-Source: 2002-07/txt/msg00123.txt.bz2 List-Id: >Number: 7201 >Category: c++ >Synopsis: Multiple inheritance from classes without data members wastes memory >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Wed Jul 03 11:06:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Markus L. Noga >Release: 2.96 20000731 (Red Hat Linux 7.3 2.96-110), 2.95.3-5 (cygwin special) >Organization: >Environment: 2.96 20000731 (Red Hat Linux 7.3 2.96-110) and 2.95.3-5 (Windows XP Professional, cygwin special) >Description: Classes without data members occupy at least one byte, even if they do not require a vtable pointer: class X1 {}; -> sizeof(X1)==1 When inheriting from classes without data member, the mysterious bytes add up: class X2 {}; class X3 : public X1, public X2 {}; -> sizeof(X3)==2 They even persist when finally inheriting from a class with data members: class X4 { int i; }; class X5 : public X3, public X4 {}; -> sizeof(X5)==8 (due to alignment) Forcing packed structures does not change this. >How-To-Repeat: #include class X1 {}; class X2 {}; class X3 : public X1, public X2 {}; class X4 { int i; }; class X5 : public X3, public X4 {}; int main(int argc, char **argv) { cout << sizeof(X1) << endl; cout << sizeof(X2) << endl; cout << sizeof(X3) << endl; cout << sizeof(X4) << endl; cout << sizeof(X5) << endl; return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: