Bug 24791 - ICE on invalid instantiation of template's static member
Summary: ICE on invalid instantiation of template's static member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, ice-on-invalid-code, monitored
: 20133 28316 28897 30234 30721 30722 32308 33046 33093 34447 34822 35181 37970 (view as bug list)
Depends on:
Blocks: 28639 28641
  Show dependency treegraph
 
Reported: 2005-11-11 09:43 UTC by Michael Haubenwallner
Modified: 2008-12-30 01:18 UTC (History)
15 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-08-30 03:40:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner 2005-11-11 09:43:26 UTC
tracked down sample is:

$ cat xx.cc

template < int I >
struct A
{
        int get_val() const;

        static int val_;
};

template< int I >
int A<I>::get_val() const
{
        return val_;
}

template< int I >    // this is invalid: works with "template <>"
int A<0>::val_(0);

// must instantiate to get ICE
template class A<0>;


$ g++ -v
Reading specs from /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: /tools/snapshot/src/sapc154/toolsbox-3.5.1.4pre.20051110/buildroot/gcc/gcc-3.4.4/configure --with-gnu-as --with-gnu-ld --enable-threads=posix --with-as=/tools/snapshot/toolsbox-3.5.1.4pre.20051110//i686-pc-linux-gnu/bin/as --with-ld=/tools/snapshot/toolsbox-3.5.1.4pre.20051110//i686-pc-linux-gnu/bin/ld --with-local-prefix=/tools/snapshot/toolsbox-3.5.1.4pre.20051110/ --disable-nls --prefix=/tools/snapshot/toolsbox-3.5.1.4pre.20051110/
Thread model: posix
gcc version 3.4.4

$ g++ -v -c xx.cc
Reading specs from /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: /tools/snapshot/src/sapc154/toolsbox-3.5.1.4pre.20051110/buildroot/gcc/gcc-3.4.4/configure --with-gnu-as --with-gnu-ld --enable-threads=posix --with-as=/tools/snapshot/toolsbox-3.5.1.4pre.20051110//i686-pc-linux-gnu/bin/as --with-ld=/tools/snapshot/toolsbox-3.5.1.4pre.20051110//i686-pc-linux-gnu/bin/ld --with-local-prefix=/tools/snapshot/toolsbox-3.5.1.4pre.20051110/ --disable-nls --prefix=/tools/snapshot/toolsbox-3.5.1.4pre.20051110/
Thread model: posix
gcc version 3.4.4
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../libexec/gcc/i686-pc-linux-gnu/3.4.4/cc1plus -quiet -v -iprefix /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/ -D_GNU_SOURCE xx.cc -quiet -dumpbase xx.cc -mtune=pentiumpro -auxbase xx -version -o /tmp/ccuQDWYE.s
ignoring nonexistent directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110//lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4"
ignoring duplicate directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110//lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/i686-pc-linux-gnu"
ignoring duplicate directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110//lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/backward"
ignoring duplicate directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110//lib/gcc/i686-pc-linux-gnu/3.4.4/include"
ignoring nonexistent directory "/tools/snapshot/toolsbox-3.5.1.4pre.20051110//lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/i686-pc-linux-gnu
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/backward
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110/bin/../lib/gcc/i686-pc-linux-gnu/3.4.4/include
 /tools/snapshot/toolsbox-3.5.1.4pre.20051110//include
 /usr/include
End of search list.
GNU C++ version 3.4.4 (i686-pc-linux-gnu)
        compiled by GNU C version 3.4.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
xx.cc:18: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Volker Reichelt 2005-11-17 10:39:17 UTC
Confirmed.

The following code snippet causes an ICE since 2.95.3
with the exception of 4.0.0 - 4.0.2:

==================================
template<int> struct A
{
    static int i;
    A() { ++i; }
};

template<int> int A<0>::i(0);

A<0> a;
==================================

The following variation causes an ICE since 4.0.0 (and before 3.1)
and is accepted by GCC 3.1 - 3.4.5:

==================================
template<int> struct A
{
    static int i;
};

template<int> int A<0>::i(0);
==================================
Comment 2 Volker Reichelt 2006-07-12 16:14:08 UTC
*** Bug 28316 has been marked as a duplicate of this bug. ***
Comment 3 Volker Reichelt 2006-08-15 19:07:15 UTC
Btw, the ICE for the second testcase in comment #1 happens in
instantiate_decl, at cp/pt.c:11875
Comment 4 Richard Biener 2006-08-30 09:43:17 UTC
*** Bug 28897 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2006-12-16 20:28:19 UTC
*** Bug 30234 has been marked as a duplicate of this bug. ***
Comment 6 Volker Reichelt 2007-02-09 00:32:40 UTC
Comment #3 is not quite correct:

The ICE for the first testcase in comment #1 is in
instantiate_decl, at cp/pt.c:12204

The ICE for the second testcase in comment #1 is in
import_export_decl, at cp/decl2.c:1956
Comment 7 Volker Reichelt 2007-02-09 00:33:52 UTC
*** Bug 30722 has been marked as a duplicate of this bug. ***
Comment 8 Volker Reichelt 2007-02-09 00:34:56 UTC
*** Bug 30721 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2007-06-12 19:02:24 UTC
*** Bug 32308 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2007-08-11 11:27:53 UTC
*** Bug 33046 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2007-08-16 21:01:20 UTC
*** Bug 33093 has been marked as a duplicate of this bug. ***
Comment 12 Jason Merrill 2007-10-26 19:54:22 UTC
Subject: Bug 24791

Author: jason
Date: Fri Oct 26 19:54:10 2007
New Revision: 129660

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129660
Log:
        PR c++/24791
        * pt.c (get_template_info): New fn.
        (template_class_depth): Use it.
        (push_template_decl_real): Check that the template args of the
        definition match the args of the previous declaration.

Added:
    trunk/gcc/testsuite/g++.dg/template/error33.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/g++.old-deja/g++.pt/crash11.C

Comment 13 Volker Reichelt 2007-10-28 21:27:03 UTC
Fixed by Jason's patch.
Comment 14 Volker Reichelt 2007-10-28 21:31:27 UTC
*** Bug 20133 has been marked as a duplicate of this bug. ***
Comment 15 Andrew Pinski 2007-12-12 23:24:54 UTC
*** Bug 34447 has been marked as a duplicate of this bug. ***
Comment 16 Andrew Pinski 2008-01-17 02:19:21 UTC
*** Bug 34822 has been marked as a duplicate of this bug. ***
Comment 17 Andrew Pinski 2008-02-13 17:33:48 UTC
*** Bug 35181 has been marked as a duplicate of this bug. ***
Comment 18 Volker Reichelt 2008-12-30 01:18:05 UTC
*** Bug 37970 has been marked as a duplicate of this bug. ***