When should value parameters be destroyed?

Martin von Loewis loewis at informatik.hu-berlin.de
Sun Oct 1 18:58:36 UTC 2000


> Why not?  `foo' has a parameter of type `A'.  It's supposed to be
> destroyed before `foo' returns, so it would seem the destructor is
> used there.  

As Daveed originally pointed out, 5.2.2/4 says

# The lifetime of a parameter ends when the function in which it is
# defined returns. The initialization and destruction of each
# parameter occurs within the context of the calling function.

So the call to the constructor actually occurs in the caller. As for
where it is "used", 3.2/2 (that normally defines when something is
"used") says

# A destructor for a class is used as specified in 12.4.

Now, 12.4 uses the verb "used" in a number of places. The place that
appears to be the normative definition of when the destructor is used
is 12.4/1:

# A destructor is used to destroy objects of its class type.

Since destruction occurs "within in the calling function", I'd say
that the inline destructor must only be defined in that context.

> That said, I don't see the space advantages as minor, and I do see the
> changes to existing implementations as significant, so I would prefer
> we honor existing practice, if that's what everybody already does.

Unfortunately, different compilers do it differently. So I'd first
take standard compliance as a guidance. If that does not determine a
decision, I'd go for efficiency (which, in terms of space, favors
destruction by the callee).

Regards,
Martin




More information about the cxx-abi-dev mailing list