Bug 7051 – Class member with un-@safe destructor gives confusing error
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-12-02T09:30:00Z
Last change time
2013-07-02T09:39:35Z
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2011-12-02T09:30:38Z
Consider:
---
struct Foo {
~this() {}
}
@safe {
class Bar {
Foo f;
}
}
---
DMD 2.057 Git (887dda0ba) fails with:
---
Error: safe function '~this' cannot call system function '~this'
---
I didn't think about what the best solution for this yet (what exactly is a »safe class« in the first place?), but the error message should certainly be improved.
[related to issue 7050]
Comment #1 by timon.gehr — 2011-12-02T09:56:21Z
a @safe class is a class that has only safe members.
This design minimizes the annotation overhead for safe code, because you can mark every function and method in a module as @safe simply by writing
@safe:
at the top.
The error message should certainly be improved though.
Comment #2 by code — 2011-12-02T09:59:08Z
@Timon: Yes, that's the intuitive meaning of it, but is this actually documented somewhere?
Comment #3 by timon.gehr — 2011-12-02T10:11:46Z
Actually I think it is undocumented, but Andrei might have mentioned it in one of his articles iirc. SafeD is generally underspecified.
But I think @safe should certainly transitively apply to members.
Comment #4 by hsteoh — 2013-07-02T09:38:17Z
The error message has improved in git HEAD:
/tmp/test.d(6): Error: safe function 'test.Bar.~this' cannot call system function 'test.Foo.~this'
Should this issue be resolved?