C++ PATCH: PR 13663

Mark Mitchell mark@codesourcery.com
Mon Jan 26 20:17:00 GMT 2004


This patch fixes PR c++/13663.  It turns out that we weren't applying
appropriate semantic constraints to the update expression appearing in
a for-statement.

Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-01-26  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13663
	* semantics.c (finish_for_expr): Check for unresolved overloaded
	functions.

2004-01-26  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13363
	* g++.dg/expr/for1.C: New test.

Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.384
diff -c -5 -p -r1.384 semantics.c
*** cp/semantics.c	26 Jan 2004 17:41:50 -0000	1.384
--- cp/semantics.c	26 Jan 2004 20:07:02 -0000
*************** finish_for_cond (tree cond, tree for_stm
*** 676,685 ****
--- 676,692 ----
     given by FOR_STMT.  */
  
  void
  finish_for_expr (tree expr, tree for_stmt)
  {
+   /* If EXPR is an overloaded function, issue an error; there is no
+      context available to use to perform overload resolution.  */
+   if (expr && type_unknown_p (expr))
+     {
+       cxx_incomplete_type_error (expr, TREE_TYPE (expr));
+       expr = error_mark_node;
+     }
    FOR_EXPR (for_stmt) = expr;
  }
  
  /* Finish the body of a for-statement, which may be given by
     FOR_STMT.  The increment-EXPR for the loop must be
Index: testsuite/g++.dg/expr/for1.C
===================================================================
RCS file: testsuite/g++.dg/expr/for1.C
diff -N testsuite/g++.dg/expr/for1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/expr/for1.C	26 Jan 2004 20:07:05 -0000
***************
*** 0 ****
--- 1,14 ----
+ // PR c++/13663
+ 
+ struct S {
+   void f();
+ };
+ 
+ void g(int);
+ void g(double);
+ 
+ void h () {
+   S s;
+   for (;;s.f); // { dg-error "" }
+   for (;;g); // { dg-error "" }
+ }



More information about the Gcc-patches mailing list