Commit d02dbde6 by Jason Merrill Committed by Jason Merrill

re PR c++/5247 (Memory eating infinite loop on default parameter in constructor…

re PR c++/5247 (Memory eating infinite loop on default parameter in constructor which is reference to class)

        PR c++/5247
        * call.c (convert_default_arg): Detect recursion.

From-SVN: r129681
parent 1200489c
2007-10-27 Jason Merrill <jason@redhat.com>
PR c++/5247
* call.c (convert_default_arg): Detect recursion.
2007-10-27 Jakub Jelinek <jakub@redhat.com>
PR c++/33842
......
......@@ -4672,9 +4672,14 @@ cxx_type_promotes_to (tree type)
the indicated TYPE, which is a parameter to FN. Do any required
conversions. Return the converted value. */
static GTY(()) VEC(tree,gc) *default_arg_context;
tree
convert_default_arg (tree type, tree arg, tree fn, int parmnum)
{
int i;
tree t;
/* If the ARG is an unparsed default argument expression, the
conversion cannot be performed. */
if (TREE_CODE (arg) == DEFAULT_ARG)
......@@ -4685,6 +4690,15 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
return error_mark_node;
}
/* Detect recursion. */
for (i = 0; VEC_iterate (tree, default_arg_context, i, t); ++i)
if (t == fn)
{
error ("recursive evaluation of default argument for %q#D", fn);
return error_mark_node;
}
VEC_safe_push (tree, gc, default_arg_context, fn);
if (fn && DECL_TEMPLATE_INFO (fn))
arg = tsubst_default_argument (fn, type, arg);
......@@ -4711,6 +4725,8 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
arg = convert_for_arg_passing (type, arg);
}
VEC_pop (tree, default_arg_context);
return arg;
}
......
// PR c++/5247
template<typename T>
int foo (T t, int = foo(T()));
int main()
{
foo(0); // { dg-error "default argument" }
}
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