__attribute__((__aligned__(16))) is applied to an empty base class, used just to propagate that and new/delete operators, not defined in the example (do you remember SSE...). If derived class T is smaller than the alignment, it is obeyed so arrays of T give aligned alements. If size of T is bigger that alignment, elements in T[] are unaligned. If base is not empty, it works ok. Is this expected behaviour ? Release: gcc-3.2.2 Environment: Linux Mandrake 9.1 How-To-Repeat: #include <iostream> using namespace std; #define __class class __attribute__((__aligned__(16))) __class A { public: void id() { cout << this << endl; }; }; class T : public A { public: // with 3 floats, sizeof(T)==16 // with 5 floats, sizeof(T)==20 float f[5]; }; int main() { A a; cout << "sizeof(A) = " << sizeof(A) << endl; cout << &a << endl; A aa[2]; cout << "sizeof(A[2]) = " << sizeof(aa) << endl; cout << &aa[0] << endl; cout << &aa[1] << endl; T t; cout << "sizeof(T) = " << sizeof(T) << endl; cout << &t << endl; T tt[2]; cout << "sizeof(T[2]) = " << sizeof(tt) << endl; cout << &tt[0] << endl; cout << &tt[1] << endl; return 0; }
Hello, I can confirm that the behavior you observed still occurs on gcc 3.3 branch and mainline (20030525). Unfortunately, someone with a better grasp of alignment will have to determine if this is in fact a bug or not... Dara
I can confirm this.
Bitten and confirmed. gcc-4.1.1 (from cellsdk-2.0).
Also present in mainline as of 20070406.
Subject: Bug 10179 Author: jason Date: Fri Sep 28 18:07:57 2007 New Revision: 128871 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128871 Log: PR c++/10179 * class.c (layout_empty_base): Take rli parameter, update rli->record_align if empty base has user-specified alignment. (build_base_field): Pass rli to it. Added: trunk/gcc/testsuite/g++.dg/ext/align2.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/class.c
Fixed for 4.3.0.
*** Bug 34747 has been marked as a duplicate of this bug. ***