Topic: stack unwinding
Author: inpact3 <inpact3@clr34el.der.edf.fr>
Date: 1997/12/03 Raw View
Hello,
I have trouble with stack-unwinding as defined in CD2 : in
[except.ctor], it is said that destructors are invoked only
for "fully constructed" objects and sub-object.
The problem arise for objects initialized as aggregates (see
[dcl.init.aggr]) : I'am inclined to think (albeit i can't find
such statement in CD2) that aggregates are said "fully
constructed" iff initialization for all members is done.
If i am right, the following program should produce no output :
char * source() { throw 0; }
main ()
{
struct local
{
~local () { cout << "destruction" << endl;
delete [] data; }
char * data;
} aux = { source() };
}
Sun CC compiler agrees, but IBM xlC doesn't.
So, which compiler is right ?
Thanks for your help,
Jerome CHAROUSSET
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Fergus Henderson <fjh@cs.mu.oz.au>
Date: 1997/12/03 Raw View
inpact3 <inpact3@clr34el.der.edf.fr> writes:
>I have trouble with stack-unwinding as defined in CD2 : in
>[except.ctor], it is said that destructors are invoked only
>for "fully constructed" objects and sub-object.
>
>The problem arise for objects initialized as aggregates (see
>[dcl.init.aggr]) : I'am inclined to think (albeit i can't find
>such statement in CD2) that aggregates are said "fully
>constructed" iff initialization for all members is done.
Yes. I couldn't find it in the Nov 97 draft either.
But I think that's the only reasonable interpretation of the draft.
Ideally the wording ought to be clarified.
>If i am right, the following program should produce no output :
>
> char * source() { throw 0; }
> main ()
> {
> struct local
> {
> ~local () { cout << "destruction" << endl;
> delete [] data; }
> char * data;
> } aux = { source() };
> }
>
>Sun CC compiler agrees, but IBM xlC doesn't.
>
>So, which compiler is right ?
I think IBM xLC is wrong and Sun CC is right.
But the wording is sufficiently vague that I would advise you to
avoid code like that.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "V.A.Neelesh" <v_a_neelesh@hotmail.com>
Date: 1997/12/03 Raw View
Hi,
char * source() { throw 0; }
main ()
{
struct local
{
~local () { cout << "destruction" << endl;
delete [] data; }
char * data;
} aux = { source() };
}
The above program will not compile coz 'return'statement is missing from
the function char char * source() { throw 0; }
But if some how we modify the above program to return character pointer
then the destructor will get called. Certainly.
Cheers
Neelesh
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/12/04 Raw View
"V.A.Neelesh" <v_a_neelesh@hotmail.com> writes:
> char * source() { throw 0; }
> main ()
> {
> struct local
> {
> ~local () { cout << "destruction" << endl;
> delete [] data; }
> char * data;
> } aux = { source() };
> }
>The above program will not compile coz 'return'statement is missing from
>the function char char * source() { throw 0; }
If that is the case, then your compiler is broken.
The only things wrong with the above program are that
(a) `main' should be declared to return an int, and
(b) you need to add
#include <iostream>
using std;
>But if some how we modify the above program to return character pointer
>then the destructor will get called. Certainly.
Why are you so certain?
An citation of appropriate parts of the (draft) standard --- or at
least an explanation of the reasons for your belief --- would count for
a lot more than simply stating your opinion, no matter how forcefully ;-)
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/12/04 Raw View
V.A.Neelesh wrote:
>
> Hi,
> char * source() { throw 0; }
> main ()
incorrect declaration
> {
> struct local
> {
> ~local () { cout << "destruction" << endl;
> delete [] data; }
> char * data;
> } aux = { source() };
> }
> The above program will not compile coz 'return'statement is missing from
> the function char char * source() { throw 0; }
No return is needed. If the compilers refuse the program
because of that, then it's a bug. If it outputs a warning,
then it's a just a bad quality compiler.
> But if some how we modify the above program to return character pointer
> then the destructor will get called. Certainly.
There is no certainty in the std here, and if there was one,
it would be that the dtor isn't called. Certainly.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "V.A.Neelesh" <v_a_neelesh@hotmail.com>
Date: 1997/12/06 Raw View
> If that is the case, then your compiler is broken.
Yes Microsoft Compiler does not have the facility of 'Exception
specification' (15.4)
Secondly as far as standard is concerned u can have exception specifed
while declaring function i.e char* source() int(); is acceptable.
But the above code is char* source() {throw 0}; - and I could not figure
out where the standard specifies that u can define a function without a
return statement(except if function returns void).
The standard 15.2 says that for a partially constructed object, the
destructor will be executed only for the fully constructed subobjects.
In that sense the destructor should not get called.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: miker3@ix.netcom.com (Michael Rubenstein)
Date: 1997/12/06 Raw View
On 06 Dec 97 05:45:47 GMT, "V.A.Neelesh" <v_a_neelesh@hotmail.com>
wrote:
>Secondly as far as standard is concerned u can have exception specifed
>while declaring function i.e char* source() int(); is acceptable.
>But the above code is char* source() {throw 0}; - and I could not figure
>out where the standard specifies that u can define a function without a
>return statement(except if function returns void).
The draft doesn't exactly specify that one can define a non void
function without a return statement -- it simply never requires a
return statement in any function.
At least, as I read the draft, a conforming compiler must accept the
program
int f()
{
}
int main()
{
}
The definition of f() is legal -- calling the function would result in
undefined behavior, but since it is never called there is no problem.
main() does not require a return for a different reason; falling off
the end of main is a special case which is equivalent to return 0.
Michael M Rubenstein
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]