[Bug c++/40092] solution in cp_tree_equal (was Re: [Bug c++/40092] New: -std=gnu++0x expansion pattern fails with error about derived template instead of actual template

Larry Evans cppljevans@suddenlink.net
Wed Aug 12 14:12:00 GMT 2009


On 05/10/09 11:20, cppljevans at suddenlink dot net wrote:
> When compile trysto expand:
> 
>   : seq
>   < integral_c
>     < Integral
>     , Vals
>     >...
> 
> the error diagnostic prints integral_c<T, val> instead of 
> integral_c<Integral,Vals>.  The integral_constant template
> is derived from integral_c and does have T and val args:
> 
> struct integral_constant:public mpl::integral_c < T, val >
> 
> However, when that is replaced with:
> 
> struct integral_constant;//:public mpl::integral_c < T, val >
> 
> Compilation succeeds.
> 
> 

When cp_tree_equal in cp/tree.c at around line 1903 is changed to:

>     case TEMPLATE_PARM_INDEX:
>       {
>         if (TEMPLATE_PARM_IDX (t1) != TEMPLATE_PARM_IDX (t2)) return false;
> 	if (TEMPLATE_PARM_LEVEL (t1) != TEMPLATE_PARM_LEVEL (t2)) return false;
>       #if 1
> 	if (TEMPLATE_PARM_PARAMETER_PACK (t1) != TEMPLATE_PARM_PARAMETER_PACK (t2)) return false;
>       #endif
> 	return same_type_p ( TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
> 			     TREE_TYPE (TEMPLATE_PARM_DECL (t2)));
>       }
> 

the test passes.  Apparently, when the test:

> 	  if (comp_template_args (TREE_PURPOSE (spec), args))

at around line pt.c:962 is executed, it passes when it shouldn't
and selects a previous instantiation with different value for
TEMPLATE_PARM_PARAMETER_PACK.  This different instantiation leads
to the failure of the test in:

>       if (TEMPLATE_PARM_PARAMETER_PACK (t))
>         parameter_pack_p = true;

at round pt.c:2463 which causes the error message.



More information about the Gcc-bugs mailing list