This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12377] New: Empty base out of class boundaries


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12377

           Summary: Empty base out of class boundaries
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: grigory at stl dot sarov dot ru
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux

Using the 3.2-compatable ABI implementation (-fabi_version=1) g++ compiler may 
alocate empty virtual base out of class boundaries. That seems to be a bug 
rather than a specific implementation.

Let's see: on class hierarchy listed below, g++ 3.3.1 produces class c17 of 
size 16 but allocates c17::c10::c0 base at offset 28.

$ cat foo.cpp
struct c0 { };
struct c2 {
    unsigned char m1;
};
struct c5 : c0, virtual c2 { };
struct c6 { };
struct c9 : c5, c6 { };
struct c10 :
    virtual c2,
    virtual c5,
    virtual c0,
    c9
{
};
struct c17 : virtual c10, c6 { };


$ g++ -c -fdump-class-hierarchy foo.cpp
Class c17
   size=16 align=4
c17 (0x4032d400) 0
    vptridx=0 vptr=((&c17::_ZTV3c17) + 24)
  c10 (0x4032d440) 0 nearly-empty virtual canonical
	...
    c0 (0x4032d5c0) 28 empty virtual canonical

Of cource an empty base does not take any space there, but the class object 
become logically invalid and potentially may lead to run-time problems.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]