Displaying 3 results from an estimated 3 matches for "stopown".
2014 Sep 25
5
[LLVMdev] New type of smart pointer for LLVM
...f (condition1) {
f(p); // takes ownership of p
}
p->SomeMethod();
if (condition2) {
return nullptr; // Leak!
}
g(p); // don't take ownership of p
return p;
}
The preferred solution would look like:
{
smart_ptr<T> p(new T);
if (condition1) {
f(p.StopOwn()); // takes ownership of p
}
p->SomeMethod();
if (condition2) {
return nullptr; //
}
g(p.Get()); // don't take ownership of p
return p.StopOwn();
}
Neither unique_ptr nor shared_ptr can be used in the place of smart_ptr
as unique_ptr sets the raw pointer to nullp...
2014 Sep 25
2
[LLVMdev] New type of smart pointer for LLVM
...return nullptr; // Leak!
> > }
> >
> > g(p); // don't take ownership of p
> > return p;
> > }
> >
> > The preferred solution would look like:
> > {
> > smart_ptr<T> p(new T);
> > if (condition1) {
> > f(p.StopOwn()); // takes ownership of p
>
> So this takes ownership, but promises not to destroy the pointee in some
> way?
>
> > }
> > p->SomeMethod();
> >
> > if (condition2) {
> > return nullptr; //
>
> I guess p is sometimes destroyed here, depen...
2014 Oct 01
4
[LLVMdev] New type of smart pointer for LLVM
...p->SomeMethod();
>
> if (condition2) {
> return nullptr; // Leak!
> }
>
> g(p); // don't take ownership of p
> return p;
> }
>
> The preferred solution would look like:
> {
> smart_ptr<T> p(new T);
> if (condition1) {
> f(p.StopOwn()); // takes ownership of p
> }
> p->SomeMethod();
>
> if (condition2) {
> return nullptr; //
> }
>
> g(p.Get()); // don't take ownership of p
> return p.StopOwn();
> }
>
> Neither unique_ptr nor shared_ptr can be used in the place of smar...