Bug 22202 – Wrong error message for implicit call to @system copy constructor in @safe code

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-11T22:25:29Z
Last change time
2022-04-19T09:25:52Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2021-08-11T22:25:29Z
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 ---
Comment #1 by dlang-bot — 2022-04-19T07:34:12Z
@RazvanN7 created dlang/dmd pull request #14015 "Fix Issue 22202 - Wrong error message for implicit call to @system copy constructor in @safe code" fixing this issue: - Fix Issue 22202 - Wrong error message for implicit call to @system copy constructor in @safe code https://github.com/dlang/dmd/pull/14015
Comment #2 by dlang-bot — 2022-04-19T09:25:52Z
dlang/dmd pull request #14015 "Fix Issue 22202 - Wrong error message for implicit call to @system copy constructor in @safe code" was merged into master: - 3d2488c630efae642bbfaf23e7f1fa743cc14857 by RazvanN7: Fix Issue 22202 - Wrong error message for implicit call to @system copy constructor in @safe code https://github.com/dlang/dmd/pull/14015