[Issue 20726] New: @safe function can modify __gshared data if passed as ref parameter default value

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 8 20:02:02 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20726

          Issue ID: 20726
           Summary: @safe function can modify __gshared data if passed as
                    ref parameter default value
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: zorael at gmail.com

Manjaro/Arch x86_64, dmd v2.091.0 but also all dmd compilers v2.060 up to
current on run.dlang.io.

This passes and __gshared `gshared` is modified by `foo`.


```
__gshared int gshared = 42;

void foo(ref int i = gshared) @safe
{
    ++i;
}

void main()
{
    assert(gshared == 42);
    foo();
    assert(gshared == 43);
}
```

--


More information about the Digitalmars-d-bugs mailing list