Program

#include <stdio.h>

struct A
{
  A() { printf( "%p %p\n", &buf[0], this ); }
  A( int j ) : i(j) { printf( "%p %p\n", &buf[0], this ); }
  A( const A& a ) : i(a.i) { printf( "%p %p\n", &buf[0], this ); }
  A& operator =( const A& a ) { printf( "%p %p\n", &buf[0], this ); return
*this; }
  A& operator =( int j ) { printf( "%p %p\n", &buf[0], this ); return *this; }

  ~A() { printf( "%p %p\n", &buf[0], this ); }

  int i;
  char buf[2];
};

struct B
{
  A a1;
};

const A a1 = 1;

int main()
{
  printf( "-- 0\n" );
  {
    const B b[] = { {a1} };
  }
  printf( "-- 1\n" );
  {
    const B b;
  }
  printf( "-- 2\n" );

  return 0;
}

give output like

0x8049b1c 0x8049b18
-- 0
0xbfd9a6a8 0xbfd9a6a4  // !!!
0xbfd9a6b8 0xbfd9a6b4  // !!!
-- 1
0xbfd9a6a8 0xbfd9a6a4
0xbfd9a6a8 0xbfd9a6a4
-- 2
0x8049b1c 0x8049b18

i.e. &*this and &buf[0] are differ in dtor and ctor in case of array
initialization with aggregate.


-- 
           Summary: array initialization
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hidden_peak at mail dot ru
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to