Sent from my iPhone

On Oct 2, 2008, at 2:09 AM, "adam at os dot inf dot tu-dresden dot de" <[EMAIL PROTECTED]> wrote:

I've been experiencing some (for me) rather unexpected behavior with some C++
code. The following is a very reduced test case:

This comes down to non pod vs pod and tail filling.



class A
{ private: void *one;
} __attribute__((aligned(16)));

class C {};
class L { public: class M : A { C _c; }; M m; };

L x;

It's about the size of L::M. I.e. if this file is compiled, L::M has a sizeof of 16. If the first private is changed to public, the size of L::M changes to 32 (-Dprivate=public). Is this expected behavior? When removing the alignment
contraints, the size of L::M is 8 in both cases.

I'm seeing this behavior with all gcc versions tested (3.3, 3.4, 4.1, 4.2, 4.3, head) as well as with different target architectures (i386, x86_64, arm).

This is the script use to show the difference:
#! /bin/sh

echo 'print sizeof(L::M)' > x.cmd

echo -n "orig:        "
gcc -Wall -g -c x.cc
gdb -x x.cmd -batch x.o

echo -n "with define: "
gcc -Dprivate=public -Wall -g -c x.cc
gdb -x x.cmd -batch x.o

Thanks


--
Summary: Different class sizes with public/private and alignments
          Product: gcc
          Version: 4.3.1
           Status: UNCONFIRMED
         Severity: normal
         Priority: P3
        Component: c++
       AssignedTo: unassigned at gcc dot gnu dot org
       ReportedBy: adam at os dot inf dot tu-dresden dot de
GCC build triplet: i486-linux-gnu
 GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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

Reply via email to