Created on 1999-05-20.00:00:00 last changed 196 months ago
[Moved to DR at 4/02 meeting.]
Proposed resolution (04/01):
In 6.7.3 [basic.life] paragraph 1, change
If T is a class type with a non-trivial constructor (11.4.5 [class.ctor]), the constructor call has completed.
to
If T is a class type with a non-trivial constructor (11.4.5 [class.ctor]), the initialization is complete. [Note: the initialization can be performed by a constructor call or, in the case of an aggregate with an implicitly-declared non-trivial default constructor, an aggregate initialization (9.4.2 [dcl.init.aggr]).]
Jack Rouse: 6.7.3 [basic.life] paragraph 1 includes:
The lifetime of an object is a runtime property of the object. The lifetime of an object of type T begins when:Consider the code:
- storage with the proper alignment and size for type T is obtained, and
- if T is a class type with a non-trivial constructor (11.4.5 [class.ctor] ), the constructor call has completed.
struct B { B( int = 0 ); ~B(); }; struct S { B b1; }; int main() { S s = { 1 }; return 0; }In the code above, class S does have a non-trivial constructor, the default constructor generated by the compiler. According the text above, the lifetime of the auto s would never begin because a constructor for S is never called. I think the second case in the text needs to include aggregate initialization.
Mike Miller: I see a couple of ways of fixing the problem. One way would be to change "the constructor call has completed" to "the object's initialization is complete."
Another would be to add following "a class type with a non-trivial constructor" the phrase "that is not initialized with the brace notation (9.4.2 [dcl.init.aggr] )."
The first formulation treats aggregate initialization like a constructor call; even POD-type members of an aggregate could not be accessed before the aggregate initialization completed. The second is less restrictive; the POD-type members of the aggregate would be usable before the initialization, and the members with non-trivial constructors (the only way an aggregate can acquire a non-trivial constructor) would be protected by recursive application of the lifetime rule.
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 | status: ready -> dr |
2001-11-09 00:00:00 | admin | set | status: review -> ready |
2001-05-20 00:00:00 | admin | set | messages: + msg483 |
2001-05-20 00:00:00 | admin | set | status: drafting -> review |
2000-11-18 00:00:00 | admin | set | messages: + msg417 |
2000-11-18 00:00:00 | admin | set | status: open -> drafting |
1999-05-20 00:00:00 | admin | create |