[Issue 10201] "= void" initialization should not be allowed in @safe
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jul 26 13:05:22 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10201
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #2 from monarchdodra at gmail.com 2013-07-26 13:05:21 PDT ---
(In reply to comment #1)
> So it is not that dangerous in that sense, but can be used to workaround some
> guarantees provided by disabled constructor. Prohibiting all void initalizers
> in @safe may be both more simple and consistent.
It is dangerous in the sense that for a struct that is not POD, you are
violating its internal integrity, at which point, it has no way to guarantee
the safety of its own internal operations.
I mentioned this in
https://github.com/D-Programming-Language/phobos/pull/1434#issuecomment-21644766
with the example:
//----
struct S
{
private size_t index;
private ubyte[1] arr;
ref ubyte get() @trusted
{
return arr.ptr[index];
}
}
void main() @safe
{
S s = void;
ubyte a = s.get();
}
//----
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list