C++ Logo

sg12

Advanced search

Re: [ub] type punning through congruent base class?

From: David Krauss <david_work_at_[hidden]>
Date: Fri, 17 Jan 2014 21:45:37 +0800
On Jan 17, 2014, at 8:42 PM, Gabriel Dos Reis <gdr_at_[hidden]> wrote:

> In C++, there is a relationship between the lifetime of a complete object and that of its subobjects – the only exception I know of is that of arrays, which has it th opposite way (wrong!) and is on my list of things to get fixed (already reported that in the past.) I don’t understand the bit about new-expression.

It sounds like both cases are covered by §3.8/2:
[ Note: The lifetime of an array object starts as soon as storage with proper size and alignment is obtained, and its lifetime ends when the storage which the array occupies is reused or released. 12.6.2 describes the lifetime of base and member subobjects. — end note ]

As for arrays, yes that sounds backwards. If the lifetime of the whole array starts before initialization finishes, that might imply something crazy like the ability to destroy all of it in the middle of initialization. (I don’t know what normative text makes the note correct, though.)

As for objects of class types, [class.base.init] 12.6.2 only seems to mention initialization, not lifetimes in the abstract sense, but I was only talking about objects with trivial initialization, for which initialization plays no part in determining lifetime.

Am I missing something else?


Received on 2014-01-17 14:45:59