Topic: DR 6.6 [stmt.jump] and 5.2.2 [expr.call]


Author: James Kanze <kanze@gabi-soft.de>
Date: Mon, 19 Mar 2001 21:22:39 GMT
Raw View
6.6 [stmt.jump] and 5.2.2 [expr.call], paragraph 4 apparently
contradict one another.

In 6.6/2, it says that "On exit from a scope (however accomplished),
destructors are called for all constructed objects with automatic
storage duration (named objects or temporaries) that are declared in
that scope, in the reverse order of their declaration."  (While I'm at
it, what does "reverse order of their declaration" mean for
temporaries?)  This means that when returning from a function, either
by means of the return statement or by leaving the scope, the
functions parameters must be destructed "in the reverse order of their
DECLARATION", ie from right to left.

In 5.2.2/4, however, it says that "The initialization and destruction
of each parameter occurs in the context of the calling function."
Presumably, this means that the order of destruction is also
determined from the calling function, and should be in the reverse
order of construction (and of course, the order of construction is
unspecified).

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh   ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627


======================================= MODERATOR'S COMMENT:
 As the subject line of this post is not in the standard format
for Defect Reports, this message has not been forwarded to the
committee.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Geoff Summerhayes" <sNuOmSrPnAoMt@hNoOtSmPaAiMl.com>
Date: Tue, 20 Mar 2001 21:12:14 GMT
Raw View
"James Kanze" <kanze@gabi-soft.de> wrote in message news:86ofuxqzcv.fsf@alex.gabi-soft.de...
> 6.6 [stmt.jump] and 5.2.2 [expr.call], paragraph 4 apparently
> contradict one another.
>
> In 6.6/2, it says that "On exit from a scope (however accomplished),
> destructors are called for all constructed objects with automatic
> storage duration (named objects or temporaries) that are declared in
> that scope, in the reverse order of their declaration."  (While I'm at
> it, what does "reverse order of their declaration" mean for
> temporaries?)  This means that when returning from a function, either
> by means of the return statement or by leaving the scope, the
> functions parameters must be destructed "in the reverse order of their
> DECLARATION", ie from right to left.
>
> In 5.2.2/4, however, it says that "The initialization and destruction
> of each parameter occurs in the context of the calling function."
> Presumably, this means that the order of destruction is also
> determined from the calling function, and should be in the reverse
> order of construction (and of course, the order of construction is
> unspecified).

I fail to see a contradiction here, I think you may be confusing
the levels.

For example,

int foo(A a)
{
B b;
C c(b); // this is the why behind the reverse order
...
return 0;
}

int main()
{
...
foo(3);
...
}

gives:

construct A from 3 in main's scope
call foo
construct B in foo's scope
construct C in foo's scope
on exit from foo's scope
destroy C
destroy B
return from foo
destroy A in main's scope

Geoff


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Thu, 22 Mar 2001 02:52:49 GMT
Raw View
In article <86ofuxqzcv.fsf@alex.gabi-soft.de>, James Kanze says...

>6.6 [stmt.jump] and 5.2.2 [expr.call], paragraph 4 apparently
>contradict one another.
>
>In 6.6/2, it says that "On exit from a scope (however accomplished),
>destructors are called for all constructed objects with automatic
>storage duration (named objects or temporaries) that are declared in
>that scope, in the reverse order of their declaration."
[SNIP]
>This means that when returning from a function, either
>by means of the return statement or by leaving the scope, the
>functions parameters must be destructed "in the reverse order of their
>DECLARATION", ie from right to left.
>
>In 5.2.2/4, however, it says that "The initialization and destruction
>of each parameter occurs in the context of the calling function."
>Presumably, this means that the order of destruction is also
>determined from the calling function, and should be in the reverse
>order of construction (and of course, the order of construction is
>unspecified).

>--
>James Kanze                               mailto:kanze@gabi-soft.de

>======================================= MODERATOR'S COMMENT:
> As the subject line of this post is not in the standard format
>for Defect Reports, this message has not been forwarded to the
>committee.


Assuming that the DR is put into the right format, the suggested
wording could be:
"On exit from a scope (however accomplished), destructors are called
for all objects with automatic storage duration (named objects or
temporaries) that are declared and constructed in that scope, ... ".

This makes it clear that destruction happens only for newly constructed
objects, and pre-exisiting objects remain untouched. I'm wondering
if we should state "declared and constructed",given James'comment on
declaring temporaries. So perhaps another wording is:
"destructors are called for all objects with automatic storage duration
(named objects or temporaries) that are constructed in that scope, ..."


Michiel Salters

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]