D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10758 - Unsound type checking for inout.
Summary: Unsound type checking for inout.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull
Depends on:
Blocks:
 
Reported: 2013-08-04 16:01 UTC by timon.gehr
Modified: 2014-09-14 15:06 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 timon.gehr 2013-08-04 16:01:37 UTC
With DMD, inout can be used to coerce away immutability as follows:

int* foo(inout(int)* x)@safe{
    inout(int)* screwUp(inout(int)*){ return x; }
    return screwUp((int*).init);
}

void main(){
    immutable x = 123;
    static assert(is(typeof(*&x)==immutable));
    assert(*&x==123);
    immutable(int)* y = &x;
    *foo(y)=456;
    assert(*&x==456);
    assert(x!=*&x); // (!)
}
Comment 2 github-bugzilla 2013-08-18 16:40:58 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/988eae63db3be236428f7753dee0812ef6aed5ec
fix Issue 10758 - Unsound type checking for inout
Comment 3 timon.gehr 2013-08-19 03:06:54 UTC
The patch misses to take into consideration inout member functions. Eg. the following function still manages to unsafely coerce its argument to mutable:

int* foo(inout(int)* x)@safe{
    struct S{ inout(int)* screwUp()inout{ return x; } }
    return S().screwUp();
}
Comment 4 Kenji Hara 2013-08-20 19:42:48 UTC
(In reply to comment #3)
> The patch misses to take into consideration inout member functions. Eg. the
> following function still manages to unsafely coerce its argument to mutable:
> 
> int* foo(inout(int)* x)@safe{
>     struct S{ inout(int)* screwUp()inout{ return x; } }
>     return S().screwUp();
> }

https://github.com/D-Programming-Language/dmd/pull/2487
Comment 5 github-bugzilla 2013-08-27 13:18:03 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a61e407fa9fa7e20e8035f41d4c26569e06b5ed8
Additional fix issue 10758 for inout method of nested aggregate

https://github.com/D-Programming-Language/dmd/commit/0542bbb77850e65a206b625970dc8b33ff6fe2fb
Merge pull request #2487 from 9rnsr/fix_inout

Additional fix issue 10758 for inout method of nested aggregate