------- Comment #28 from rguenther at suse dot de 2009-04-09 07:58 ------- Subject: Re: C++ empty struct is passed incorrectly
On Wed, 8 Apr 2009, hjl dot tools at gmail dot com wrote: > ------- Comment #23 from hjl dot tools at gmail dot com 2009-04-08 23:41 > ------- > This looks like an ABI issue: > > [...@gnu-6 pr39678]$ cat pr39678.c > #include <stdio.h> > > struct Y {}; > struct X { > struct Y y; > __complex__ float val; > }; > > struct X __attribute__((noinline)) > foo (float *p) > { > struct X x; > __real x.val = p[0]; > __imag x.val = p[1]; > return x; > } > #ifdef __cplusplus > extern "C" > #endif > void abort (void); > float a[2] = { 3., -2. }; > int main() > { > struct X x = foo(a); > printf ("X: %d\n", (int) sizeof (struct X)); > printf ("Y: %d\n", (int) sizeof (struct Y)); > if (__real x.val != 3.) > abort (); > if (__imag x.val != -2.) > abort (); > return 0; > } > [...@gnu-6 pr39678]$ gcc pr39678.c > [...@gnu-6 pr39678]$ ./a.out > X: 8 > Y: 0 > [...@gnu-6 pr39678]$ g++ pr39678.c > [...@gnu-6 pr39678]$ ./a.out > X: 12 > Y: 1 > Aborted > [...@gnu-6 pr39678]$ > > "struct Y {};" isn't handled properly in C++. sizeof(Y) is 1 according to the C++ standard. Richard. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39678