[cfe-dev] Use of Smart Pointers in LLVM Projects
Zachary Turner
zturner at google.com
Thu Jul 17 20:20:08 PDT 2014
On Thu, Jul 17, 2014 at 4:58 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Thu, Jul 17, 2014 at 4:45 PM, Alp Toker <alp at nuanti.com> wrote:
> > In many cases there shouldn't be a need for smart pointers at all,
> because
> > the object is owned by a central facility's smart pointer so it's safe to
> > just pass around the pointer in ephemeral contexts like stack-based
> > instances. In such context raw pointers and references aren't scary --
> > they're just fine.
>
> There's no contention there - if the pointer is non-owning, there's no
> smart pointer to use. Indeed using a smart pointer for a non-owning
> pointer would actually break the code by causing double deletes, etc.
>
> Well, shared_ptr notwithstanding - but, yes, choosing between
> unique_ptr + non-owning pointers and shared_ptr can sometimes be
> non-obvious, but I'm hopeful we generally agree that if there is a
> dominating owner they can be given exclusive ownership through a
> unique_ptr and everyone else can use raw pointers.
What about weak_ptr?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140717/bd77f2a8/attachment.html>
More information about the cfe-dev
mailing list