---- struct S { void f1(immutable int* x, int* y) @safe { *y = 13; } } void main() @safe { S s; void delegate(immutable int*, int*) @safe d = &s.f1; void function(immutable int*, int*) @safe f = d.funcptr; /* uh-oh */ immutable int* x = new int(42); assert(*x == 42); /* passes */ f(x, new int); assert(*x == 42); /* fails */ } ----
(In reply to ag0aep6g from comment #0) > S s; > void delegate(immutable int*, int*) @safe d = &s.f1; > void function(immutable int*, int*) @safe f = d.funcptr; /* uh-oh */ Can also use `f = &S.f1;` to obtain the unsafe function pointer.
partial fix: https://github.com/dlang/dmd/pull/6072
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3eece2fe875d35db428229b1121eda13e85b3883 partial solution for Issue 16365 - cannot allow calling function pointer from delegate in @safe code https://github.com/dlang/dmd/commit/627e96b986c9d94feefa5145a077eb2f820a3bef Merge pull request #6072 from WalterBright/fix16365-1 partial solution for Issue 16365 - cannot allow calling function poin…
Related PR: https://github.com/dlang/dmd/pull/5860
https://github.com/dlang/dmd/pull/6085
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/497fdfbee1b376d049d0531da789dbc60860fe1f fix Issue 16365 - cannot allow calling function pointer from delegate in @safe code https://github.com/dlang/dmd/commit/fe0ab0df5cfe4aa9c1ec4ea140e5521767e28df5 Merge pull request #6085 from WalterBright/fix16365 fix Issue 16365 - cannot allow calling function pointer from delegate…
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3eece2fe875d35db428229b1121eda13e85b3883 partial solution for Issue 16365 - cannot allow calling function pointer from delegate in @safe code https://github.com/dlang/dmd/commit/627e96b986c9d94feefa5145a077eb2f820a3bef Merge pull request #6072 from WalterBright/fix16365-1 https://github.com/dlang/dmd/commit/497fdfbee1b376d049d0531da789dbc60860fe1f fix Issue 16365 - cannot allow calling function pointer from delegate in @safe code https://github.com/dlang/dmd/commit/fe0ab0df5cfe4aa9c1ec4ea140e5521767e28df5 Merge pull request #6085 from WalterBright/fix16365