This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Issue errors on invalid use of non-static memfn in build_new_op (PR c++/29225)


Hi!

On the following invalid testcase g++ doesn't emit diagnostics and
crashes at gimplification time on unexpected trees in fn body.

Most of the functions that call build_over_call call resolve_args
to ensure the arguments are sane (and that calls
invalid_nonstatic_memfn_p).  But build_new_op only checks for
error_operand_p early (e.g. because code can be CALL_EXPR in which
case that is valid for arg1) and doesn't do any checking when it finds
an operator it wants to use.

Fixed by calling resolve_args before the build_over_call.
Regtested on x86_64-linux, ok for trunk?

2007-11-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/29225
	* call.c (build_new_op): Call resolve_args before calling
	build_over_call.

	* g++.dg/template/crash72.C: New test.

--- gcc/cp/call.c.jj	2007-11-07 20:25:28.000000000 +0100
+++ gcc/cp/call.c	2007-11-12 17:15:12.000000000 +0100
@@ -3918,7 +3918,10 @@ build_new_op (enum tree_code code, int f
 	  if (overloaded_p)
 	    *overloaded_p = true;
 
-	  result = build_over_call (cand, LOOKUP_NORMAL);
+	  if (resolve_args (arglist) == error_mark_node)
+	    result = error_mark_node;
+	  else
+	    result = build_over_call (cand, LOOKUP_NORMAL);
 	}
       else
 	{
--- gcc/testsuite/g++.dg/template/crash72.C.jj	2007-11-12 17:25:09.000000000 +0100
+++ gcc/testsuite/g++.dg/template/crash72.C	2007-11-12 17:21:56.000000000 +0100
@@ -0,0 +1,25 @@
+// PR c++/29225
+// { dg-do compile }
+
+template <typename L, typename R> bool operator< (L x, R y);
+struct T { int t (); };
+class S {};
+
+struct U
+{
+   typedef int (T::* M) ();
+   M m;
+
+   bool operator() (S &x)
+   {
+     T a;
+     return (a.*m) < x;	// { dg-error "invalid use of non-static member" }
+   }
+};
+
+void foo (S &x)
+{
+  U m;
+  m.m = &T::t;
+  m (x);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]