<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 16, 2014 at 2:21 PM, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 01/16/2014 11:05 PM, Matt Austern wrote:<br>
> That's an interesting possibility that I hadn't considered. It's definitely appealing in some ways, but I think that it, too, would imply some pretty big surgery in some pretty fundamental parts of the standard. So let's consider the following code snippet:<br>
> struct MyPOD { int x; }; // 1<br>
> void* vp = malloc(sizeof(MyPOD)); // 2<br>
> MyPOD* p1 = static_cast<MyPOD*>(vp); // 3<br>
> MyPOD* p2 = new MyPOD; // 4<br>
><br>
> So the basic question I'd ask is: after line 4, what are you allowed<br>
> to do with p1 and what are allowed to do with p2, and how do the<br>
> answers differ? We've got a couple of choices.<br>
><br>
> First choice: we decide that you aren't allowed to do anything that<br>
> involves dereferencing p1, since p1 doesn't point to an object.<br>
<br>
</div>Please don't confuse "object" with "lifetime".<br>
<br>
1.8p1 says an object is a region of storage. Both *p1 and<br>
*p2 satisfy that.<br></blockquote><div><br></div><div>That's an interesting observation. It's also true, of course, that</div><div> void* vp = malloc(12);</div><div>creates a region of storage and thus, by the definition in 1.8p1,</div>
<div>creates an object. I'm a little reluctant to say that this line</div><div>creates an object of type T, though, no matter what T is. Maybe</div><div>we have subtly different concepts of "object", "object of type T",</div>
<div>and "object whose lifetime has begun". Or maybe we need to</div><div>make those subtle distinctions even we aren't currently making</div><div>them.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Further, 3.8p1 seems to say that the lifetime of both *p1 and *p2<br>
has begun.</blockquote><div><br></div><div>I agree that 3.8p1 seems to say that. Not everyone seems to</div><div>agree that it says that, though; some people also seem to think</div><div>that even if it does say that, it shouldn't. I sympathize. That</div>
<div>reading of 3.8p1 has some surprising consequences. (But every</div><div>proposed alternative I can think of seems to have some</div><div>surprising consequences too.)</div><div><br></div><div> --Matt</div>
</div></div></div>