public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to convert_default_arg for c++/5247
@ 2007-10-27 16:07 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2007-10-27 16:07 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Another frequently reported bug.  In this one the compiler got into an 
infinite recursion trying to evaluate a recursive default argument.

Tested x86_64-pc-linux-gnu, applied to trunk.


[-- Attachment #2: 5247.patch --]
[-- Type: text/x-patch, Size: 1928 bytes --]

2007-10-27  Jason Merrill  <jason@redhat.com>

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

Index: cp/call.c
===================================================================
*** cp/call.c	(revision 129660)
--- cp/call.c	(working copy)
*************** cxx_type_promotes_to (tree type)
*** 4672,4680 ****
--- 4672,4685 ----
     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)
*************** convert_default_arg (tree type, tree arg
*** 4685,4690 ****
--- 4690,4704 ----
        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);
  
*************** convert_default_arg (tree type, tree arg
*** 4711,4716 ****
--- 4725,4732 ----
        arg = convert_for_arg_passing (type, arg);
      }
  
+   VEC_pop (tree, default_arg_context);
+ 
    return arg;
  }
  
Index: testsuite/g++.dg/overload/defarg1.C
===================================================================
*** testsuite/g++.dg/overload/defarg1.C	(revision 0)
--- testsuite/g++.dg/overload/defarg1.C	(revision 0)
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/5247
+ 
+ template<typename T>
+ int foo (T t, int = foo(T()));
+ 
+ int main()
+ {
+   foo(0);			// { dg-error "default argument" }
+ }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-10-27 15:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-27 16:07 C++ PATCH to convert_default_arg for c++/5247 Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).