www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22202] New: Wrong error message for implicit call to system

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

          Issue ID: 22202
           Summary: Wrong error message for implicit call to  system copy
                    constructor in  safe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

Example program:

---
struct SystemCopy
{
    this(ref inout SystemCopy other) inout {}
}

void fun(SystemCopy)  safe {}

void main()  safe
{
    SystemCopy s;
    fun(s);
}
---

As of DMD 2.097.0, attempting to compile this program yields the following
error message:

---
onlineapp.d(11): Error: function `onlineapp.fun(SystemCopy _param_0)` is not
callable using argument types `(SystemCopy)`
onlineapp.d(11):        `struct SystemCopy` does not define a copy constructor
for `SystemCopy` to `SystemCopy` copies
---

This message is incorrect. fun is callable with an argument of type SystemCopy,
and SystemCopy does define a copy constructor.

The actual error is that the function call `fun(s)` requires an implicit call
to SystemCopy's copy constructor, which is  system and therefore cannot be
called from main, which is  safe.

The same incorrect error message is also given if  safe is replaced with either
pure or  nogc.

Replacing  safe with nothrow, however, results in a correct error message:

---
onlineapp.d(11): Error: copy constructor `onlineapp.SystemCopy.this` is not
`nothrow`
onlineapp.d(8): Error: `nothrow` function `D main` may throw
---

--
Aug 11