This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix C++ diagnostic ICE on invalid method call
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 22 Jun 2010 15:50:07 +0200
- Subject: [C++ PATCH] Fix C++ diagnostic ICE on invalid method call
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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