From patchwork Tue Jun 22 13:50:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] Fix C++ diagnostic ICE on invalid method call Date: Tue, 22 Jun 2010 03:50:07 -0000 From: Jakub Jelinek X-Patchwork-Id: 56499 Message-Id: <20100622135007.GR7811@tyan-ft48-01.lab.bos.redhat.com> To: Jason Merrill Cc: gcc-patches@gcc.gnu.org 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 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 --- 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 +void +bar () +{ + A::foo ().anything; // { dg-error "request for member" } +} + +void +baz () +{ + bar (); +}