This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Ensure destructor calls have type "void"
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 19 Feb 2007 23:31:48 -0800
- Subject: C++ PATCH: Ensure destructor calls have type "void"
- Reply-to: mark at codesourcery dot com
In some internal testing, we noticed that
g++.dg/template/dependent-expr1.C was failing on ARM ABI targets. The
problem turned out to be that the C++ front-end was treating an
expression of the form "x->~X()" as having type "void *", rather than
"void" as the ISO C++ standard requires. The cause was that, in the
ARM ABI, [cd]tors return "void *" (the "this" pointer). Because we
don't have a separate C++ lowering phase, we must be careful to
convert to the correct type.
Tested on arm-none-eabi, applied to the mainline. I shall also apply
shortly to 4.1 and 4.2 branches, since this is a regression.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2007-02-19 Mark Mitchell <mark@codesourcery.com>
* call.c (build_new_method_call): Ensure that explicit calls of
destructors have type "void".
Index: call.c
===================================================================
--- call.c (revision 121831)
+++ call.c (working copy)
@@ -5520,6 +5520,20 @@ build_new_method_call (tree instance, tr
&& TREE_SIDE_EFFECTS (instance_ptr))
call = build2 (COMPOUND_EXPR, TREE_TYPE (call),
instance_ptr, call);
+ else if (call != error_mark_node
+ && DECL_DESTRUCTOR_P (cand->fn)
+ && !VOID_TYPE_P (TREE_TYPE (call)))
+ /* An explicit call of the form "x->~X()" has type
+ "void". However, on platforms where destructors
+ return "this" (i.e., those where
+ targetm.cxx.cdtor_returns_this is true), such calls
+ will appear to have a return value of pointer type
+ to the low-level call machinery. We do not want to
+ change the low-level machinery, since we want to be
+ able to optimize "delete f()" on such platforms as
+ "operator delete(~X(f()))" (rather than generating
+ "t = f(), ~X(t), operator delete (t)"). */
+ call = build_nop (void_type_node, call);
}
}
}