Attributes lost in TypeInfo, please advise
Jakob Ovrum via Digitalmars-d
digitalmars-d at puremagic.com
Wed Feb 11 20:08:22 PST 2015
Consider the following:
---
struct S
{
~this() @safe {}
}
void foo() @safe
{
S s;
// OK
}
void bar() @safe
{
S s;
destroy(s);
// test.d(15): Error: safe function 'test.bar' cannot call
system function 'object.destroy!(S).destroy'
}
---
`destroy` is used in algorithms using low-level operations like
`emplace[Ref]`, and while `destroy` itself is a template and thus
enjoys attribute inference, it calls the non-generic
typeid(T).destroy function, which is unconditionally @system.
This unsafety then propagates all the way up to high-level code
that is otherwise inferred to be safe.
The `postblit` TypeInfo method, used from `emplace[Ref]`, has the
same problem.
Is it possible to call the destructor or postblit constructor
directly, and will they correctly destruct/copy recursively like
TypeInfo.destroy/postblit do? If so, we should change `destroy`
and `emplaceImpl` to use direct calls ASAP.
More information about the Digitalmars-d
mailing list