Topic: local static destruction order


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/04/24
Raw View
Martin von Loewis <loewis@informatik.hu-berlin.de> writes:

> This looks like a defect to me. There might be alternative fixes, but
> making it undefined looks reasonable.

Following up to myself: This was discussed in a committee
meeting. Quoting from

http://anubis.dkuug.dk/JTC1/SC22/open/n2833.htm

>> Myers wanted clarification about static objects constructed during
>> exit processing. Gibbons said this should be undefined too.

Martin


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/04/21
Raw View
scott douglass <sdouglass%_%junk@_.arm.com> writes:

> A simple fix would be to declare it undefined behavior if a local static was
> constructed after main returned or exit was called.  But I can't see anywhere
> that the standard says that.

This looks like a defect to me. There might be alternative fixes, but
making it undefined looks reasonable.

Regards,
Martin


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/04/21
Raw View
Is the destruction order of the following defined?  Section 3.6.3 of the
standard doesn't specifically address it and can be interpreted as inconsistent.

  struct T { ~T(); } t;
  struct S { ~S(); };
  void f() { static S s; }
  T::~T() { f(); }

Section 3.6.3 of the standard specifically lets the implementation off the hook
if 'f' is called after 's' has been destroyed.  But imagine that 'f' has never
been called and 't' is being destroyed.  's' gets constructed by the call to 'f'
and now the standard requires that 's' be destroyed before 't' since the
construction of 's' completed after the construction of 't' but it's too late
for that.

Similar problems occur if 'f' is registered with atexit (or called from a
function registered with atexit).

A simple fix would be to declare it undefined behavior if a local static was
constructed after main returned or exit was called.  But I can't see anywhere
that the standard says that.

Deja News reveals some discussion of local static destruction in June 1996 but
nothing that answers my question.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]