The general form of this bug seems (to my untrained eye) to be that when a static member of a template class is declared correctly but initialised incorrectly, GCC gets confused. I've found two ways of triggering what appears to be the same bug - * A * By causing an error with the line: static int n = 1; gcc does the following: test.cc:6: ISO C++ forbids in-class initialization of non-const static member ` n' test.cc: In instantiation of `foo<1>': test.cc:17: instantiated from here test.cc:6: ISO C++ forbids in-class initialization of non-const static member ` foo<1>::n' g++-3.2: Internal error: Segmentation fault (program cc1plus) Please submit a full bug report. See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions. For Debian GNU/Linux specific bugs, please see /usr/share/doc/debian/bug-reporting.txt. * B * By causing an error with the line: static const int n = unsigned char(1); gcc does the following: $ g++-3.2 -Wall test.cc test.cc:7: parse error before `char' g++-3.2: Internal error: Segmentation fault (program cc1plus) Please submit a full bug report. See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions. For Debian GNU/Linux specific bugs, please see /usr/share/doc/debian/bug-reporting.txt. Release: 3.2.1 (Debian testing/unstable) Environment: System: Linux nautilus 2.4.19 #1 Fri Nov 1 18:58:16 GMT 2002 i686 unknown unknown GNU/Linux Architecture: i686 host: i386-pc-linux-gnu build: i386-pc-linux-gnu target: i386-pc-linux-gnu configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux How-To-Repeat: Contents of pre-processed file test.ii in case A: # 1 "test.cc" # 1 "<built-in>" # 1 "<command line>" # 1 "test.cc" template <int i> class foo { public: static int n = 1; char text[n]; foo(); }; int main() { foo<1> e; return 0; }; Contents of pre-processed file test.ii in case B: # 1 "test.cc" # 1 "<built-in>" # 1 "<command line>" # 1 "test.cc" template <int i> class foo { public: static const int n = unsigned char(1); char text[n]; foo(); }; int main() { foo<1> e; return 0; };
Fix: Write correct code :)
State-Changed-From-To: open->analyzed State-Changed-Why: I can confirm this. It is a regression of present 3.2 branch vs 3.2.0. Too bad :-( The symptom on my machine is that it enters a memory eating loop and only dies if it is killed or runs out of memory.
From: Joe Buck <jbuck@synopsys.com> To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, andrew-message@ccl.bham.ac.uk, bangerth@ticam.utexas.edu Cc: Subject: Re: c++/8766: [3.2->3.2.2 regression] cc1plus segfaults after failed initialisation of static template variable Date: Fri, 24 Jan 2003 17:40:40 -0800 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8766 Both test cases (A and B) work with gcc 3.2.0, fail with gcc 3.2.1 and the current 3_2_branch, and work in 3_3_branch and trunk.
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for 3.3.