This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Moved to DR at 4/01 meeting.]
Jack Rouse:6.8.7 [class.temporary]states that temporary objects will normally be destroyed at theend of the full expression in which they are created. This can createsome unique code generation requirements when initializing a classarray with a default constructor that uses a default argument. Considerthe 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 inf(int) includes thedefault constructor forS. Therefore according to6.10.1 [intro.execution] paragraph 14, itincludes the default argument expression forS(int).So evaluation ofthe full expression should include evaluating the default argument "n"times and creating "n" temporaries of typeT. But the destruction ofthe temporaries must be delayed until the end of the full expressionso this requires allocating space at runtime for "n" distincttemporaries. It is unclear how these temporaries are supposed to beallocated and deallocated. They cannot readily be autos because avariable allocation is required.I believe that many existing implementations will destroy thetemporaries needed by the default constructor after each array elementis initialized. But I can't find anything in the standard that allowsthe temporaries to be destroyed early in this case.
I think the standard should allow the early destruction of temporariesused in the default initialization of class array elements. I believeearly destruction is the status quo, and I don't think the users ofexisting C++ compilers have been adversely impacted by it.
Proposed resolution (04/01):
The proposed resolution is contained in the proposal forissue 201.