}
/* Call the trivial destructor for INSTANCE, which can be either an lvalue of
- class type or a pointer to class type. */
+ class type or a pointer to class type. If NO_PTR_DEREF is true and
+ INSTANCE has pointer type, clobber the pointer rather than what it points
+ to. */
tree
-build_trivial_dtor_call (tree instance)
+build_trivial_dtor_call (tree instance, bool no_ptr_deref)
{
gcc_assert (!is_dummy_object (instance));
return fold_convert (void_type_node, instance);
}
- if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
+ if (INDIRECT_TYPE_P (TREE_TYPE (instance))
+ && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
{
if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
goto no_clobber;
extern bool sufficient_parms_p (const_tree);
extern tree type_decays_to (tree);
extern tree extract_call_expr (tree);
-extern tree build_trivial_dtor_call (tree);
+extern tree build_trivial_dtor_call (tree, bool = false);
extern tree build_user_type_conversion (tree, tree, int,
tsubst_flags_t);
extern tree build_new_function_call (tree, vec<tree, va_gc> **,
denoted by the object expression of the class member access. */
tree ob = TREE_OPERAND (fn, 0);
if (obvalue_p (ob))
- result = build_trivial_dtor_call (ob);
+ result = build_trivial_dtor_call (ob, true);
else
/* No location to clobber. */
result = convert_to_void (ob, ICV_STATEMENT, complain);
--- /dev/null
+// PR c++/96721
+// { dg-do run }
+// { dg-options "-O2 -flifetime-dse" }
+
+typedef int *T;
+
+int
+main ()
+{
+ T a = T ();
+ a.~T ();
+}