[C++ PATCH] Fix build_new_method_call (PR c++/38577)
Jakub Jelinek
jakub@redhat.com
Fri Dec 19 21:55:00 GMT 2008
Hi!
As discussed in bugzilla, a few lines before this hunk in
build_new_method_call the code can create COMPOUND_EXPR or NOP_EXPR,
on which CALL_EXPR_FN ICEs.
Approved in bugzilla by Jason, bootstrapped/regtested on x86_64-linux,
committed to trunk.
2008-12-19 Jakub Jelinek <jakub@redhat.com>
PR c++/38577
* call.c (build_new_method_call): Handle call being COMPOUND_EXPR
or NOP_EXPR.
* g++.dg/template/call6.C: New test.
--- gcc/cp/call.c.jj 2008-12-10 16:54:33.000000000 +0100
+++ gcc/cp/call.c 2008-12-19 17:34:50.000000000 +0100
@@ -5993,6 +5993,15 @@ build_new_method_call (tree instance, tr
if (processing_template_decl && call != error_mark_node)
{
+ bool cast_to_void = false;
+
+ if (TREE_CODE (call) == COMPOUND_EXPR)
+ call = TREE_OPERAND (call, 1);
+ else if (TREE_CODE (call) == NOP_EXPR)
+ {
+ cast_to_void = true;
+ call = TREE_OPERAND (call, 0);
+ }
if (TREE_CODE (call) == INDIRECT_REF)
call = TREE_OPERAND (call, 0);
call = (build_min_non_dep_call_list
@@ -6001,6 +6010,8 @@ build_new_method_call (tree instance, tr
orig_instance, orig_fns, NULL_TREE),
orig_args));
call = convert_from_reference (call);
+ if (cast_to_void)
+ call = build_nop (void_type_node, call);
}
/* Free all the conversions we allocated. */
--- gcc/testsuite/g++.dg/template/call6.C.jj 2008-12-19 17:37:07.000000000 +0100
+++ gcc/testsuite/g++.dg/template/call6.C 2008-12-19 17:25:37.000000000 +0100
@@ -0,0 +1,24 @@
+// PR c++/38577
+// { dg-do compile }
+
+struct A
+{
+ static A *bar ();
+};
+
+struct B : public A
+{
+ static void baz ();
+};
+
+template <class T>
+void foo ()
+{
+ (static_cast<B *> (A::bar ()))->baz ();
+}
+
+void
+bar ()
+{
+ foo<int> ();
+}
Jakub
More information about the Gcc-patches
mailing list