[C++] Fix C++ diagnostic ICE on invalid method call

Submitted by Jakub Jelinek on June 22, 2010, 1:50 p.m.

Details

Message ID 20100622135007.GR7811@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek June 22, 2010, 1:50 p.m.
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.


	Jakub

Comments

Jason Merrill June 22, 2010, 6:18 p.m.
OK.

Jason

Patch hide | download patch | download mbox

--- 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> ();
+}