C++ Logo

sg12

Advanced search

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

From: James Dennett <jdennett_at_[hidden]>
Date: Thu, 16 Jan 2014 12:05:57 -0800
On Thu, Jan 16, 2014 at 12:00 PM, Gabriel Dos Reis <gdr_at_[hidden]> wrote:
>
>
> | -----Original Message-----
> | From: ub-bounces_at_[hidden] [mailto:ub-bounces_at_[hidden]] On
> | Behalf Of Herb Sutter
> | Sent: Thursday, January 16, 2014 11:50 AM
> | To: WG21 UB study group
> | Subject: Re: [ub] type punning through congruent base class?
> |
> | > Well, as far as I understand, trivial constructors might not be called at all.
> |
> | Maybe "might not be called" is part of the bug then. Isn't the right model that
> | trivial ctors are called, but "might do nothing"?
>
> Yes, agreed.

That may be part of a proposed model, but it's not part of the
existing model, which (for compatibility) is based on C's model, where
fields of a (necessarily trivially-constructible) struct can be
written to as soon as suitable memory for that struct is obtained.

If C++ weren't based on C, it would likely have a model where you
could not access an object without an initialization operation to
create an object from raw memory. But C allows use of raw memory as
objects, and I don't hear anyone suggesting how we can accommodate
that while avoiding its horrible consequences. We could choose _not_
to accommodate it (i.e., require the initialization step that creates
an object from raw memory), but it's a significant change that
invalidates massive amounts of existing code.

-- James

Received on 2014-01-16 21:05:59