Created on 1999-06-03.00:00:00 last changed 196 months ago
[Moved to DR at 4/01 meeting.]
Proposed resolution (04/01):
The proposed resolution is contained in the proposal for issue 201.
Jack Rouse: 6.7.7 [class.temporary] states that temporary objects will normally be destroyed at the end of the full expression in which they are created. This can create some unique code generation requirements when initializing a class array with a default constructor that uses a default argument. Consider the code:
struct T { int i; T( int ); ~T(); }; struct S { S( int = T(0).i ); ~S(); }; S* f( int n ) { return new S[n]; }The full expression allocating the array in f(int) includes the default constructor for S. Therefore according to 6.9.1 [intro.execution] paragraph 14, it includes the default argument expression for S(int). So evaluation of the full expression should include evaluating the default argument "n" times and creating "n" temporaries of type T. But the destruction of the temporaries must be delayed until the end of the full expression so this requires allocating space at runtime for "n" distinct temporaries. It is unclear how these temporaries are supposed to be allocated and deallocated. They cannot readily be autos because a variable allocation is required.
I believe that many existing implementations will destroy the temporaries needed by the default constructor after each array element is initialized. But I can't find anything in the standard that allows the temporaries to be destroyed early in this case.
I think the standard should allow the early destruction of temporaries used in the default initialization of class array elements. I believe early destruction is the status quo, and I don't think the users of existing C++ compilers have been adversely impacted by it.
History | |||
---|---|---|---|
Date | User | Action | Args |
2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
2003-04-25 00:00:00 | admin | set | status: dr -> wp |
2002-05-10 00:00:00 | admin | set | messages: + msg683 |
2001-05-20 00:00:00 | admin | set | status: ready -> dr |
2000-11-18 00:00:00 | admin | set | status: review -> ready |
2000-05-21 00:00:00 | admin | set | messages: + msg337 |
2000-05-21 00:00:00 | admin | set | status: drafting -> review |
2000-02-23 00:00:00 | admin | set | status: open -> drafting |
1999-06-03 00:00:00 | admin | create |