D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16365 - cannot allow calling function pointer from delegate in @safe code
Summary: cannot allow calling function pointer from delegate in @safe code
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull, safe
Depends on:
Blocks:
 
Reported: 2016-08-08 10:04 UTC by ag0aep6g
Modified: 2016-10-01 11:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2016-08-08 10:04:40 UTC
----
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 */
}
----
Comment 1 ag0aep6g 2016-08-08 10:07:58 UTC
(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.
Comment 2 Walter Bright 2016-08-22 08:51:28 UTC
partial fix: https://github.com/dlang/dmd/pull/6072
Comment 3 github-bugzilla 2016-08-25 20:17:51 UTC
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…
Comment 4 Walter Bright 2016-08-25 22:43:00 UTC
Related PR: https://github.com/dlang/dmd/pull/5860
Comment 5 Walter Bright 2016-08-25 23:09:07 UTC
https://github.com/dlang/dmd/pull/6085
Comment 6 github-bugzilla 2016-08-26 14:00:11 UTC
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…
Comment 7 github-bugzilla 2016-10-01 11:48:32 UTC
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