call.c (build_new_method_call): Ensure that explicit calls of destructors have type...
authorMark Mitchell <mark@codesourcery.com>
Tue, 20 Feb 2007 07:28:35 +0000 (07:28 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 20 Feb 2007 07:28:35 +0000 (07:28 +0000)
* call.c (build_new_method_call): Ensure that explicit calls of
destructors have type "void".

From-SVN: r122153

gcc/cp/ChangeLog
gcc/cp/call.c

index 0c6b90d7edda001d58eac36bba90d2257dd6fae9..c3263933a46ac6966529d3d9d5bfaaef012c5da9 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-19  Mark Mitchell  <mark@codesourcery.com>
+
+       * call.c (build_new_method_call): Ensure that explicit calls of
+       destructors have type "void".
+
 2007-02-19  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        * typeck.c (build_binary_op): Replace -Wstring-literal-comparison
index b1b5a8e827757ba2e6e165f2e44e8d4502e618e8..f60c59260fd8b72b04eeef1ddd3ef50cd153a392 100644 (file)
@@ -5528,6 +5528,20 @@ build_new_method_call (tree instance, tree fns, tree args,
                  && 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);
            }
        }
     }