>Submitter-Id:  net
>Originator:    Andrew Sayers
>Organization:  <none>
>Confidential:  no
>Synopsis:      cc1plus segfaults after failed initialisation of static 
>template variable
>Severity:      serious
>Priority:      low
>Category:      c++
>Class:         ice-on-illegal-code
>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
>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 :)


Reply via email to