From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kriang Lerdsuwanakij To: egcs@cygnus.com Cc: martin@mira.isdn.cs.tu-berlin.de Subject: Re: Bug in coerce_template_parms (fixed patch) Date: Tue, 17 Mar 1998 13:29:00 -0000 Message-id: X-SW-Source: 1998-03/msg00586.html I think this patch is good now. It passes all testcases include the new one which can catch the bad memory access and bad use of tsubst. Kriang * pt.c (coerce_template_parms): Correctly access arguments inside TREE_VEC when NARGS < NPARMS. Don't call tsubst and friends if is_tmpl_parm is true. diff -cprN gcc-stock-980315/cp/pt.c gcc-980317/cp/pt.c *** gcc-stock-980315/cp/pt.c Tue Mar 17 09:16:38 1998 --- gcc-980317/cp/pt.c Tue Mar 17 12:54:18 1998 *************** coerce_template_parms (parms, arglist, i *** 1951,1957 **** tree arg; tree parm = TREE_VEC_ELT (parms, i); ! if (arglist) { arg = arglist; arglist = TREE_CHAIN (arglist); --- 1951,1957 ---- tree arg; tree parm = TREE_VEC_ELT (parms, i); ! if (arglist && TREE_CODE (arglist) == TREE_LIST) { arg = arglist; arglist = TREE_CHAIN (arglist); *************** coerce_template_parms (parms, arglist, i *** 1961,1967 **** else arg = TREE_VALUE (arg); } ! else if (is_tmpl_parm && i < nargs) { arg = TREE_VEC_ELT (arglist, i); if (arg == error_mark_node) --- 1961,1967 ---- else arg = TREE_VALUE (arg); } ! else if (i < nargs) { arg = TREE_VEC_ELT (arglist, i); if (arg == error_mark_node) *************** coerce_template_parms (parms, arglist, i *** 1972,1977 **** --- 1972,1980 ---- my_friendly_assert (!require_all_arguments, 0); break; } + else if (is_tmpl_parm) + /* VEC is not in the form that can be handled by tsubst. */ + arg = TREE_PURPOSE (parm); else if (TREE_CODE (TREE_VALUE (parm)) == TYPE_DECL) arg = tsubst (TREE_PURPOSE (parm), vec, in_decl); else *************** coerce_template_parms (parms, arglist, i *** 2096,2101 **** --- 2099,2106 ---- } if (is_tmpl_parm) { + /* FIXME: add checks for default arguments and nontype template + parameters here. */ if (requires_tmpl_type) { cp_error ("nested template template parameter not implemented"); diff -cprN gcc-stock-980315/testsuite/g++.old-deja/g++.pt/ttp45.C gcc-980317/testsuite/g++.old-deja/g++.pt/ttp45.C *** gcc-stock-980315/testsuite/g++.old-deja/g++.pt/ttp45.C Wed Dec 31 16:00:00 1969 --- gcc-980317/testsuite/g++.old-deja/g++.pt/ttp45.C Tue Mar 17 12:55:36 1998 *************** *** 0 **** --- 1,13 ---- + template class D + { + }; + + template class D,class E> class C + { + D d; + }; + + int main() + { + C c; + }