[cfe-dev] Parser Stmt/Expr Owning Pointer
Howard Hinnant
hhinnant at apple.com
Tue Dec 9 09:43:12 PST 2008
On Dec 9, 2008, at 11:16 AM, Sebastian Redl wrote:
> In terms of C++0x rvalue references, I've basically implemented an
> implicit conversion from "unique_ptr<void, ASTDeleter>&&" to void*
> that is equivalent to release(). Obviously, this is not possible in C
> ++0x, but since my rvalue reference is a special object, it's very
> easy.
>
> The advantage of this is that I can pass my pointer's mover to a
> function that is updated to take my pointer as easily as I can pass
> it to a function that still takes a raw pointer, with no change in
> the caller's syntax. Since the update is the business of the callee,
> I don't see this as unsafe, I see it as convenient.
> We're not redefining ownership here, we're just trying to enforce
> the existing rules through the type system. So the caller moves the
> pointer to the callee, no matter how the callee decides to handle it
> further.
People have been warning against implicit conversions from smart
pointers to raw pointers for a very long time...
http://www.aristeia.com/Papers/C++ReportColumns/jun96.pdf
> The bottom line is simple: don’t provide implicit conversion
> operators to dumb point-
> ers unless there is a compelling reason to do so.
Scott Meyers, 1996.
I realize you're only converting implicitly from an ASTMove (result of
member move). However this is at least conceptually the same as
implicitly converting from an rvalue smart pointer.
>> I'll try to get it in soon. I'm not yet positive what "in" means.
> For starters, you could send me a link. :-) I'm more interested in
> the technique, though. Using unique_ptr directly is difficult
> because we need to store the success flag alongside the pointer (and
> if I wrap unique_ptr, I need to write all the emulation stuff again
> anyway).
Info sent offline.
-Howard
More information about the cfe-dev
mailing list