Bug 10939 - [3.3/3.4 regression] ICE with templated code
Summary: [3.3/3.4 regression] ICE with templated code
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
Keywords: ice-on-valid-code
Depends on:
Reported: 2003-05-22 16:47 UTC by Theodore.Papadopoulo
Modified: 2004-01-17 04:22 UTC (History)
2 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: 2003-05-22 18:27:26

The code of the test case (148 bytes, text/plain)
2003-05-22 16:50 UTC, Theodore.Papadopoulo

Note You need to log in before you can comment on or make changes to this bug.
Description Theodore.Papadopoulo 2003-05-22 16:47:42 UTC
The following piece of code fails to compile with g++ (versions 3.2.3, 3.3 and
3.4). Those frontends generate an ICE. This is a regression form 2.95.3 which
compiled the code with no problem.

When compiled with g++-3.4, the compiler ICEs with a message (3.4 delivers the
most complete message IMHO):

argos->g++ toto.C
toto.C: In function `int main()':
toto.C:2: internal compiler error: tree check: accessed elt 2 of tree_vec with 
   1 elts in tsubst, at cp/pt.c:6683
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

If one of the template parameters T1 or T2 is removed or if the method g is made
to make a const T&, then the compiler accepts the code...

The piece of code:

template <typename T1,typename T2>
inline void f(const T1&,const T2&) { }

template <typename T1,typename T2,void F(const T1&,const T2&)>
struct A {
    template <typename T> void g(T& i) { }

int main() {
    int i;
    A<int,int,f> a;
Comment 1 Theodore.Papadopoulo 2003-05-22 16:50:27 UTC
Created attachment 4053 [details]
The code of the test case
Comment 2 Giovanni Bajo 2003-05-22 18:17:48 UTC
Confirmed, a regression. Slightly reduced testcode is:

template <typename T1, typename T2>
void f(T1,T2) {}

template <void F(int, int)>
struct A 
    template <typename Q> 
    void g(Q i) {}

int main() 
    A<f> a;
pr10939.cpp: In function `int main()':
pr10939.cpp:2: internal compiler error: tree check: accessed elt 2 of tree_vec 
with 1 elts in tsubst, at cp/pt.c:6672
Please submit a full bug report,
Comment 3 Wolfgang Bangerth 2003-05-22 18:27:26 UTC
The code Giovanni gave is illegal: you need to say A<f<int,int> > instead of
just A<f>. However, fixing this (or even writing A<&f<int,int> >) doesn't make
the ICE go away. I don't know how 2.95 could accept the illegal code, but
it's a regression in any case.

Comment 4 CVS Commits 2003-06-20 05:52:47 UTC
Subject: Bug 10939

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-06-20 05:52:44

Modified files:
	gcc/cp         : ChangeLog pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: func1.C 

Log message:
	PR c++/10939
	* pt.c (tsubst_decl): Do not try to substitute into non-dependent
	(value_dependent_expression_p): Correct logic for FUNCTION_DECLs.
	PR c++/10939
	* g++.dg/template/func1.C: New test.


Comment 5 CVS Commits 2003-06-20 05:57:26 UTC
Subject: Bug 10939

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-06-20 05:57:23

Modified files:
	gcc/cp         : ChangeLog Make-lang.in decl.c pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.other: anon7.C 
Added files:
	gcc/testsuite/g++.dg/template: func1.C static4.C 

Log message:
	PR c++/10939
	* Make-lang.in (decl.o): Depend on input.h.
	* decl.c (input.h): Include it.
	(cp_finish_decl): Revert previous change:
	2003-06-19  Mark Mitchell  <mark@codesourcery.com>
	* decl.c (cp_finish_decl): Remove support for RESULT_DECLs.
	Don't check building_stmt_tree.
	* pt.c (tsubst_decl): Do not try to substitute into non-dependent
	PR c++/10939
	* g++.dg/template/func1.C: New test.


Comment 6 Mark Mitchell 2003-06-20 05:57:57 UTC
Fixed in GCC 3.3.1, GCC 3.4.