Bug 10939 - [3.3/3.4 regression] ICE with templated code
[3.3/3.4 regression] ICE with templated code
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
3.4.0
: P2 normal
: 3.3.1
Assigned To: Not yet assigned to anyone
: ice-on-valid-code
Depends on:
Blocks:
  Show dependency treegraph
 
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


Attachments
The code of the test case (254 bytes, text/plain)
2003-05-22 16:50 UTC, theodore.papadopoulo
Details

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;
    a.g(i);
}
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;
    a.g(0);
}
------------------------------------------
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.

W.
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
	functions.
	(value_dependent_expression_p): Correct logic for FUNCTION_DECLs.
	
	PR c++/10939
	* g++.dg/template/func1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3441&r2=1.3442
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.702&r2=1.703
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2783&r2=1.2784
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/func1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

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
	functions.
	
	PR c++/10939
	* g++.dg/template/func1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.155&r2=1.3076.2.156
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/Make-lang.in.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.125.4.4&r2=1.125.4.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.50&r2=1.965.2.51
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.28&r2=1.635.2.29
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.193&r2=1.2261.2.194
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/func1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/anon7.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1.54.1&r2=1.1.54.2

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