This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8766: cc1plus segfaults after failed initialisation of static template variable
- From: Andrew Sayers <andrew-message at ccl dot bham dot ac dot uk>
- To: gcc-gnats at gcc dot gnu dot org, debian-gcc at lists dot debian dot org
- Date: Sat, 30 Nov 2002 17:16:34 +0000
- Subject: c++/8766: cc1plus segfaults after failed initialisation of static template variable
>Number: 8766
>Category: c++
>Synopsis: cc1plus segfaults after failed initialisation of static template variable
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: unassigned
>State: open
>Class: ice-on-illegal-code
>Submitter-Id: net
>Arrival-Date: Sat Nov 30 09:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Andrew Sayers
>Release: 3.2.1 (Debian testing/unstable)
>Organization:
<none>
>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
>Description:
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.
>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 :)
>Release-Note:
>Audit-Trail:
>Unformatted: