C++ Logo

sg12

Advanced search

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

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Fri, 17 Jan 2014 13:53:58 +0000
One of the things that bothers me with the array thing is that conceptually, an array is just like a structure with homogeneous elements (and we do actually tend to think of it that way in certain parts of the library, e.g. see std::complex). Furthermore, I don't see the point of this "exception".

As for an object type with "trivial initialization", I suspect that the general confusion comes from the fact for some reasons the standards text assumed that it could just "optimize" that case without much confusion. But evidence appear to suggest otherwise. Complexity has grown, with increased likelihood of inconsistency. What is the meaning of T{ } when T is a POD struct? Do you think there is no lifetime there?

From: ub-bounces_at_[hidden] [mailto:ub-bounces_at_[hidden]] On Behalf Of David Krauss
Sent: Friday, January 17, 2014 5:46 AM
To: WG21 UB study group
Subject: Re: [ub] type punning through congruent base class?


On Jan 17, 2014, at 8:42 PM, Gabriel Dos Reis <gdr_at_[hidden]<mailto: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:

1. [ 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:54:02