This code
{{{
struct vector {
  vector() : x(0), y(0), z(0) { }  
  float x,y,z;
};

struct Foo { 
  int dummy; // commenting this out makes it run perfectly
  vector array_of_vectors[4];
};

Foo foo;

int main() { }
}}}
compiled with 
  g++ -O3 test.cpp -o test
segaults on x86-64 linux (tested on arch-linux and ubuntu hardy).

Compiled it with -g
  g++ -O3 -g test.cpp -o test
gdb says
{{{
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400553 in global constructors keyed to foo () at test.cpp:2
2         vector() : x(0), y(0), z(0) { }  
(gdb) bt
#0  0x0000000000400553 in global constructors keyed to foo () at test.cpp:2
#1  0x0000000000400636 in __do_global_ctors_aux ()
#2  0x000000000040041b in _init ()
#3  0x00007fbf690ee8c0 in ?? () from /usr/lib/libstdc++.so.6
#4  0x00000000004005c5 in __libc_csu_init ()
#5  0x00007fbf688ca382 in __libc_start_main () from /lib/libc.so.6
#6  0x0000000000400479 in _start ()
(gdb) 
}}}

$ LANG=en_US /opt/bin/g++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.3.1/configure --prefix=/opt --enable-languages=c++
--disable-multilib
Thread model: posix
gcc version 4.3.1 (GCC)

Related ML threads:
  http://thread.gmane.org/gmane.linux.arch.general/16677
  http://thread.gmane.org/gmane.comp.gcc.help/24804


-- Maik


-- 
           Summary: segfault in global constructor with -O3
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: beckmann dot maik at googlemail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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

Reply via email to