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] Fix C++ diagnostic ICE on invalid method call


Hi!

On valid code obviously calls to methods need to have at least one
arguments, but on invalid code like this they sometimes don't.
The diagnostic printer should be IMHO extra careful.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-06-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/44627
	* error.c (dump_expr): Don't look at CALL_EXPR_ARG (t, 0) if
	the CALL_EXPR has no arguments.

	* g++.dg/diagnostic/method1.C: New test.

--- gcc/cp/error.c.jj	2010-06-20 16:36:49.000000000 +0200
+++ gcc/cp/error.c	2010-06-22 11:45:04.000000000 +0200
@@ -1759,7 +1759,9 @@ dump_expr (tree t, int flags)
 	if (TREE_CODE (fn) == OBJ_TYPE_REF)
 	  fn = resolve_virtual_fun_from_obj_type_ref (fn);
 
-	if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
+	if (TREE_TYPE (fn) != NULL_TREE
+	    && NEXT_CODE (fn) == METHOD_TYPE
+	    && call_expr_nargs (t))
 	  {
 	    tree ob = CALL_EXPR_ARG (t, 0);
 	    if (TREE_CODE (ob) == ADDR_EXPR)
--- gcc/testsuite/g++.dg/diagnostic/method1.C.jj	2010-06-22 11:51:31.000000000 +0200
+++ gcc/testsuite/g++.dg/diagnostic/method1.C	2010-06-22 11:56:40.000000000 +0200
@@ -0,0 +1,20 @@
+// PR c++/44627
+// { dg-do compile }
+
+struct A
+{
+  A *foo ();
+};
+
+template <class T>
+void
+bar ()
+{
+  A::foo ().anything;	// { dg-error "request for member" }
+}
+
+void
+baz ()
+{
+  bar <int> ();
+}

	Jakub


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