[Issue 22202] New: Wrong error message for implicit call to @system copy constructor in @safe code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 11 22:25:29 UTC 2021
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 at puremagic.com
Reporter: snarwin+bugzilla at 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
---
--
More information about the Digitalmars-d-bugs
mailing list