Bug 11043 – Context pointer of delegate should be const qualified

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-15T12:59:09Z
Last change time
2021-11-05T00:18:47Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Maxim Fomin
Blocks
15129
See also
https://issues.dlang.org/show_bug.cgi?id=1983

Comments

Comment #0 by maxim — 2013-09-15T12:59:09Z
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.
Comment #1 by moonlightsentinel — 2021-11-05T00:18:47Z
*** This issue has been marked as a duplicate of issue 1983 ***