[ub] new revision of p0593

Richard Smith richardsmith at googlers.com
Mon Feb 12 04:45:08 CET 2018


On Sun, 11 Feb 2018 at 19:29, Gabriel Dos Reis <gdr at microsoft.com> wrote:

> Thank you for following through!
>
> And taking care of the ‘memcpy’ and ‘memmove’ thingies.
>
>
>
> When we say that the operations implicitly creates an object, are we also
> to require that the bits patterns there be valid object representation?
> That would impose a severe restriction…
>

I think we need to allow cases like this:

struct X { int a, b; };
X *p = (X*)malloc(sizeof(X));
p->a = 1;
p->b = 2;

... where there is not necessarily a valid object representation in the *p
memory after the call to malloc, but we need for there to already be an
object there for the p->a assignment to be valid.

I think we should say that the created object -- or at least its scalar
subobjects -- contain an indeterminate value (the kind that means you get
UB if you try to read it, http://eel.is/c++draft/dcl.init#12) if the
storage doesn't contain a valid object representation.

For example, given:

char c = 7;
bool b; // assuming sizeof(b) == 1
memcpy(&b, &c, 1);

'b' should have the same behavior as an uninitialized bool, because we
"initialized" it with an invalid bool representation:

bool x = b; // undefined behavior

Does that seem reasonable to you?

*From:* ub-bounces at open-std.org [mailto:ub-bounces at open-std.org] *On Behalf
> Of *Richard Smith
> *Sent:* Friday, February 9, 2018 11:52 AM
> *To:* ub at open-std.org
> *Subject:* [ub] new revision of p0593
>
>
>
> Hi all,
>
>
>
> Please find attached a revised version of P0593 based on the excellent
> discussion and feedback at the Albuquerque meeting. Please let me know if
> you have any comments; I believe our plan was to discuss this again at
> Jacksonville, and all being well, to forward it to EWG at that meeting.
>
>
>
> Best regards,
>
> Richard
> _______________________________________________
> ub mailing list
> ub at isocpp.open-std.org
> http://www.open-std.org/mailman/listinfo/ub
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/ub/attachments/20180212/6eae35b5/attachment.html 


More information about the ub mailing list