<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 16 January 2014 14:13, Jens Maurer <span dir="ltr"><<a href="mailto:Jens.Maurer@gmx.net" target="_blank">Jens.Maurer@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 01/16/2014 10:48 PM, Richard Smith wrote:<br>
> There's one other rule that I'd overlooked in my prior messages.<br>
> [intro.object]/1 presents this beautiful model: "An object is a<br>
> region of storage. [...] An object is created by a definition (3.1),<br>
> by a new-expression (5.3.4) or by the implementation (12.2) when<br>
> needed.[...] An object has a storage duration (3.7) which influences<br>
> its lifetime (3.8). An object has a type (3.9)."<br>
><br>
> Trouble is, this model gives a vast quantity of real-world C++ code<br>
> undefined behavior, including any C-like code that uses the 'malloc'<br>
> technique described in this thread.<br>
<br>
</div>Why? Applying the term "object" to something doesn't mean it's<br>
actually usable (outside of its lifetime); see 3.8p5.<br></blockquote><div><br></div><div>Because:</div><div><br></div><div> int *p = (int*)malloc(sizeof(int));</div><div> *p = 0;</div><div><br></div><div>... does not contain a definition of an 'int', not a new-expression, nor a temporary. Therefore, by 1.8/1, it does not create an object of type 'int'. Therefore the assignment (presumably) has undefined behavior.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Put differently: 1.8p1 doesn't say anything about "lifetime", it<br>
just says "object", which is a fairly vacuous term by itself.<br>
<br>
(I concur with your earlier point that the C++ wording 3.8p1<br>
<div class="im">"storage with the proper alignment and size for type T is obtained"<br>
</div>isn't good enough, and we might need something akin to the<br>
C model of effective type, or apply the term "dynamic type"<br>
expressly for the memory-scribbling case.)<br>
<span class="HOEnZb"><font color="#888888"><br>
Jens<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
ub mailing list<br>
<a href="mailto:ub@isocpp.open-std.org">ub@isocpp.open-std.org</a><br>
<a href="http://www.open-std.org/mailman/listinfo/ub" target="_blank">http://www.open-std.org/mailman/listinfo/ub</a><br>
</div></div></blockquote></div><br></div></div>