When should value parameters be destroyed?
Jim Dehnert
dehnert at baalbek.engr.sgi.com
Thu Sep 28 22:22:01 UTC 2000
Hi, folks,
To elaborate for those of you who weren't there...
At the meeting today, we took up C-18 again, i.e. how to return results
of class types with non-trivial copy constructors. We decided in
principle to undo the C-18 decision, and return them (all sizes) via an
implicit first parameter, which was how it was previously described.
The question then arises: which classes exactly are included? We
want, for simplicity, for the answer to be the same as which classes
are passed by address when they are value parameters. 3.1.1 says this
is those with non-trivial copy constructors _or_ destructors. Those of
us present could not remember why destructors were included here, and
decided it was probably a mistake, and intend to remove it (for both
value parameters and results), if a request for rationale yields
nothing. Consider this message such a request. Mark's message is a
response:
> From: mendell at ca.ibm.com
>
> From today's meeting, it turns out that g++ destroys value parameters in
> the called
> function, and that is what the current ABI states. Our compiler (and I
> think HP's)
> destroyes them in the caller routine. I asked our 'standards guy', and got
> back the
> following:
>
> Sentence 3, paragraph 3 of 12.2: 'Temporary object are destroyed as the
> last
> step in evaluating the full-expression(1.8) that (lexically) contains
> the point where
> they were created.'
>
> Also see paragraph 12 and 16 of 1.8 and the note associated with
> paragraph 16.
>
>
> I believe that this implies that you are NOT allowed to destroy the
> temporary in the
> called routine, but must destroy it in the caller. This would mean a
> change to
> our ABI, and would explain the reason that we pass classes with non-trivial
> destructors
> by reference (unlike g++).
... and now that Mark brings it up, I do remember this discussion,
albeit vaguely, and believe it was the basis for our current definition
including destructors in the "qualifying" set for special treatment.
As Jason points out, gcc currently destroys the value parameter in the
callee, and has received no problem reports related to it. We believe
many other implementations do, too. However, the Standard as quoted
above appears to forbid that. (I can imagine ways to write code that
could tell, though I think they're in the "shoot the programmer"
class.)
So, we have two questions:
1) Can anyone present any additional grounds for passing temporaries
of classes with destructors by address?
2) Given the above (and anything additional resulting from (1)), would
anyone care to argue that we should specify that the destructor be
called from the callee (current practice)? Otherwise, I think the
current definition in 3.1.1 stands, with corrections in the 4th
bullet (copy constructor -> destructor), and it will be used for a
revised specification in 3.1.4.
Regards,
Jim
- Jim Dehnert dehnert at sgi.com
(650)933-4272
More information about the cxx-abi-dev
mailing list