[Issue 11043] New: Context pointer of delegate should be const qualified
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 15 12:59:12 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11043
Summary: Context pointer of delegate should be const qualified
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: maxim at maxim-fomin.ru
--- Comment #0 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-09-15 12:59:09 PDT ---
There is consensus that the way delegates are currently implemented
(effectively untyped void pointer + incorrectly typed function pointer without
this parameter) should be revised.
In addition to function pointer problem which is raised in issue 2672 there is
also problem with context pointer, but which is expressed not only in the fact
that it is void*, but in the fact that it is mutable.
extern(C) @system int printf(const char*, ...);
auto frame1() pure nothrow @safe
{
immutable void delegate() pure nothrow @safe x;
auto tmp = { return x; } ;
return tmp;
}
auto frame2(T)(T t) pure nothrow @safe
{
void delegate() @system x;
x.funcptr = t;
return { return x; } ;
}
void bar() { printf("pure nothrow @safe loophole\n"); } @system
void main() @safe pure nothrow
{
//bar(); Error: ...
auto fm1 = frame1();
auto fm2 = frame2(&bar);
fm1.ptr = fm2.ptr; // from type system point of view it is void*=void*
// but actually void pure nothrow @safe = @system
fm1()();
}
This prints "pure nothrow @safe loophole". It is hole not only with respect to
these attributes, but also can be used to reinterpret at runtime different
types.
--
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