Bug 8766 - [3.2.1 regression] cc1plus segfaults after failed initialisation of static template variable
Summary: [3.2.1 regression] cc1plus segfaults after failed initialisation of static te...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2002-11-30 09:26 UTC by andrew-message
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host: i386-pc-linux-gnu
Target: i386-pc-linux-gnu
Build: i386-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andrew-message 2002-11-30 09:26:00 UTC
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;
};
Comment 1 andrew-message 2002-11-30 09:26:00 UTC
Fix:
Write correct code :)
Comment 2 Wolfgang Bangerth 2002-12-02 12:30:06 UTC
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.
Comment 3 Joe Buck 2003-01-24 17:40:40 UTC
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.
 
Comment 4 Joe Buck 2003-04-25 21:53:17 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for 3.3.