[PATCH] D49985: [ADT] ImmutableList no longer requires elements to be copy constructible
Artem Dergachev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 11:12:01 PDT 2018
NoQ added a comment.
In https://reviews.llvm.org/D49985#1189306, @Szelethus wrote:
> What is very interesting though, a simple wrapper works perfectly:
>
> struct ObjRef {
> Obj *ptr;
> ObjRef(Obj *ptr) : ptr(ptr) {}
> ~ObjRef() { delete ptr; }
> Obj *get() const { return ptr; }
> };
> // llvm_unreachable is actually reached in Obj::~Obj().
>
>
> I've been stuck on this issue for a while now. Do you know anything about why this could happen?
My guess is, in your wrapper code the destructor for the //temporary// `ObjRef` at the end of the full-expression `f.create(ObjRef(new Obj))` deletes the object, and the copy of `ObjRef` within the immutable list now contains a dangling pointer to the object (from which it won't be deleted again because immutable list doesn't call destructors; your code also doesn't dereference the pointer).
Your custom wrapper doesn't define any reasonable copy/move constructors, so a default copy is used.
https://reviews.llvm.org/D49985
More information about the llvm-commits
mailing list