Commit a7c3f276 by Paolo Carlini Committed by Paolo Carlini

re PR c++/59115 (ICE with invalid template parameter)

/cp
2014-04-08  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59115
	* pt.c (process_template_parm): For an invalid non-type parameter
	only set TREE_TYPE to error_mark_node.
	(push_inline_template_parms_recursive, comp_template_parms,
	redeclare_class_template, coerce_template_template_parm,
	coerce_template_template_parms, unify): Use error_operand_p.

/testsuite
2014-04-08  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59115
	* g++.dg/template/crash119.C: New.

From-SVN: r209230
parent edb2b1b1
2014-04-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59115
* pt.c (process_template_parm): For an invalid non-type parameter
only set TREE_TYPE to error_mark_node.
(push_inline_template_parms_recursive, comp_template_parms,
redeclare_class_template, coerce_template_template_parm,
coerce_template_template_parms, unify): Use error_operand_p.
2014-04-08 Nathan Sidwell <nathan@codesourcery.com>
* class.c (check_bases_and_members): Warn about non-virtual dtors
......
......@@ -414,7 +414,7 @@ push_inline_template_parms_recursive (tree parmlist, int levels)
{
tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
if (parm == error_mark_node)
if (error_operand_p (parm))
continue;
gcc_assert (DECL_P (parm));
......@@ -2829,7 +2829,7 @@ comp_template_parms (const_tree parms1, const_tree parms2)
/* If either of the template parameters are invalid, assume
they match for the sake of error recovery. */
if (parm1 == error_mark_node || parm2 == error_mark_node)
if (error_operand_p (parm1) || error_operand_p (parm2))
return 1;
if (TREE_CODE (parm1) != TREE_CODE (parm2))
......@@ -3640,11 +3640,7 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args,
to the LIST being built. This new parameter is a non-type
parameter iff IS_NON_TYPE is true. This new parameter is a
parameter pack iff IS_PARAMETER_PACK is true. The location of PARM
is in PARM_LOC. NUM_TEMPLATE_PARMS is the size of the template
parameter list PARM belongs to. This is used used to create a
proper canonical type for the type of PARM that is to be created,
iff PARM is a type. If the size is not known, this parameter shall
be set to 0. */
is in PARM_LOC. */
tree
process_template_parm (tree list, location_t parm_loc, tree parm,
......@@ -3652,7 +3648,6 @@ process_template_parm (tree list, location_t parm_loc, tree parm,
{
tree decl = 0;
tree defval;
tree err_parm_list;
int idx = 0;
gcc_assert (TREE_CODE (parm) == TREE_LIST);
......@@ -3673,8 +3668,6 @@ process_template_parm (tree list, location_t parm_loc, tree parm,
++idx;
}
else
idx = 0;
if (is_non_type)
{
......@@ -3682,39 +3675,29 @@ process_template_parm (tree list, location_t parm_loc, tree parm,
SET_DECL_TEMPLATE_PARM_P (parm);
if (TREE_TYPE (parm) == error_mark_node)
{
err_parm_list = build_tree_list (defval, parm);
TREE_VALUE (err_parm_list) = error_mark_node;
return chainon (list, err_parm_list);
}
else
{
/* [temp.param]
The top-level cv-qualifiers on the template-parameter are
ignored when determining its type. */
TREE_TYPE (parm) = TYPE_MAIN_VARIANT (TREE_TYPE (parm));
if (invalid_nontype_parm_type_p (TREE_TYPE (parm), 1))
{
err_parm_list = build_tree_list (defval, parm);
TREE_VALUE (err_parm_list) = error_mark_node;
return chainon (list, err_parm_list);
}
if (TREE_TYPE (parm) != error_mark_node)
{
/* [temp.param]
The top-level cv-qualifiers on the template-parameter are
ignored when determining its type. */
TREE_TYPE (parm) = TYPE_MAIN_VARIANT (TREE_TYPE (parm));
if (invalid_nontype_parm_type_p (TREE_TYPE (parm), 1))
TREE_TYPE (parm) = error_mark_node;
else if (uses_parameter_packs (TREE_TYPE (parm))
&& !is_parameter_pack
/* If we're in a nested template parameter list, the template
template parameter could be a parameter pack. */
&& processing_template_parmlist == 1)
{
/* This template parameter is not a parameter pack, but it
should be. Complain about "bare" parameter packs. */
check_for_bare_parameter_packs (TREE_TYPE (parm));
if (uses_parameter_packs (TREE_TYPE (parm)) && !is_parameter_pack
/* If we're in a nested template parameter list, the template
template parameter could be a parameter pack. */
&& processing_template_parmlist == 1)
{
/* This template parameter is not a parameter pack, but it
should be. Complain about "bare" parameter packs. */
check_for_bare_parameter_packs (TREE_TYPE (parm));
/* Recover by calling this a parameter pack. */
is_parameter_pack = true;
}
}
/* Recover by calling this a parameter pack. */
is_parameter_pack = true;
}
}
/* A template parameter is not modifiable. */
TREE_CONSTANT (parm) = 1;
......@@ -5127,7 +5110,7 @@ redeclare_class_template (tree type, tree parms)
continue;
tmpl_parm = TREE_VALUE (TREE_VEC_ELT (tmpl_parms, i));
if (tmpl_parm == error_mark_node)
if (error_operand_p (tmpl_parm))
return false;
parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
......@@ -6087,8 +6070,8 @@ coerce_template_template_parm (tree parm,
tree in_decl,
tree outer_args)
{
if (arg == NULL_TREE || arg == error_mark_node
|| parm == NULL_TREE || parm == error_mark_node)
if (arg == NULL_TREE || error_operand_p (arg)
|| parm == NULL_TREE || error_operand_p (parm))
return 0;
if (TREE_CODE (arg) != TREE_CODE (parm))
......@@ -6181,7 +6164,7 @@ coerce_template_template_parms (tree parm_parms,
{
parm = TREE_VALUE (TREE_VEC_ELT (parm_parms, nparms - 1));
if (parm == error_mark_node)
if (error_operand_p (parm))
return 0;
switch (TREE_CODE (parm))
......@@ -17517,7 +17500,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
case TEMPLATE_TEMPLATE_PARM:
case BOUND_TEMPLATE_TEMPLATE_PARM:
tparm = TREE_VALUE (TREE_VEC_ELT (tparms, 0));
if (tparm == error_mark_node)
if (error_operand_p (tparm))
return unify_invalid (explain_p);
if (TEMPLATE_TYPE_LEVEL (parm)
......@@ -17535,7 +17518,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
idx = TEMPLATE_TYPE_IDX (parm);
targ = TREE_VEC_ELT (INNERMOST_TEMPLATE_ARGS (targs), idx);
tparm = TREE_VALUE (TREE_VEC_ELT (tparms, idx));
if (tparm == error_mark_node)
if (error_operand_p (tparm))
return unify_invalid (explain_p);
/* Check for mixed types and values. */
......@@ -17718,7 +17701,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
case TEMPLATE_PARM_INDEX:
tparm = TREE_VALUE (TREE_VEC_ELT (tparms, 0));
if (tparm == error_mark_node)
if (error_operand_p (tparm))
return unify_invalid (explain_p);
if (TEMPLATE_PARM_LEVEL (parm)
......
2014-04-08 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59115
* g++.dg/template/crash119.C: New.
2014-04-08 Pat Haugen <pthaugen@us.ibm.com>
* gcc.target/powerpc/atomic_load_store-p8.c: New.
......
// PR c++/59115
template<typename T, float, int, typename U> void foo(T, U) {} // { dg-error "valid type" }
void bar()
{
foo(0, 0); // { dg-error "matching" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment