g++ 4.2.4 (more precisely the package "g++-4.2" version 4.2.4-3ubuntu4 from Ubuntu 8.10 amd64) receives a SIGSEGV when compiling the following snippet of code with -O3. It does NOT crash with -O2 or less optimization. The 4.3 branch ("g++-4.3" 4.3.2-1ubuntu11) also does NOT crash. This bug seems similar to bug 28058 but I am not sure how closely related they are. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28058
// compile with "g++ -O3 -c test.cpp" template<class T> class A { public: A(); }; template<class T> class B : protected A<T> { public: B(); }; template class B<void>; // commenting out this line prevents the segfault template<class T> B<T> ::B() : A<T> () {} template<> B<void>::B() : A<void>() {} I recompiled g++ from source to get a stack trace: $ gdb ./build/gcc/cc1plus GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later < http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu"... (gdb) r -O3 test.cpp Starting program: /home/mrb/tmp/comp-4.2/gcc-4.2-4.2.4/build/gcc/cc1plus -O3 test.cpp B<T>::B() B<T>::B() [with T = void] B<T>::B() [with T = void] B<T>::B() [with T = void] Analyzing compilation unit Program received signal SIGSEGV, Segmentation fault. 0x00000000004bd689 in tree_inlinable_function_p (fn=0x7f1267299700) at ../../src/gcc/tree-inline.c:1467 1467 FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (fndecl)) (gdb) bt #0 0x00000000004bd689 in tree_inlinable_function_p (fn=0x7f1267299700) at ../../src/gcc/tree-inline.c:1467 #1 0x00000000007ceb1d in cgraph_analyze_function (node=0x7f126723ea80) at ../../src/gcc/cgraphunit.c:955 #2 0x00000000007cf2f5 in cgraph_finalize_compilation_unit () at ../../src/gcc/cgraphunit.c:1122 #3 0x0000000000441aea in cp_finish_file () at ../../src/gcc/cp/decl2.c:3356 #4 0x00000000004b69ea in c_common_parse_file (set_yydebug=<value optimized out>) at ../../src/gcc/c-opts.c:1193 #5 0x000000000076aac3 in toplev_main (argc=<value optimized out>, argv=<value optimized out>) at ../../src/gcc/toplev.c:1032 #6 0x00007f1267331466 in __libc_start_main () from /lib/libc.so.6 #7 0x0000000000402779 in _start () $ g++-4.2 -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.2.4 (Ubuntu 4.2.4-3ubuntu4) -- Summary: g++ 4.2 SIGSEGV in tree_inlinable_function_p Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: m dot bevand at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38211