[Issue 24705] New: Arguments of synchronized method are unintentionally treated as shared with -preview=nosharedaccess

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 16 07:31:54 UTC 2024


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

          Issue ID: 24705
           Summary: Arguments of synchronized method are unintentionally
                    treated as shared with -preview=nosharedaccess
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: komatsu.kazuki.op at tut.jp

The following code should compile without error even with
-preview=nosharedaccess, but in fact the argument `int n` is treated as shared,
resulting in an error.
I have confirmed that all dmd compilers from version 2.088.1 to 2.100.2 (and
also in the current nightly) have the same bug.


```d
// $ dmd test.d -preview=nosharedaccess
class MyClass
{
    synchronized void foo(int n)
    {
        // Error: direct access to shared `n` is not allowed, see `core.atomic`
        int a = n;
    }
}

void main() {}
```

--


More information about the Digitalmars-d-bugs mailing list