fix Issue 16747 - Cannot have stack allocated classes in @safe code#6279
fix Issue 16747 - Cannot have stack allocated classes in @safe code#6279MartinNowak merged 1 commit intodlang:stablefrom
Conversation
51141eb to
9a21dd6
Compare
test/fail_compilation/test16747.d
Outdated
| void fwd() @safe | ||
| { | ||
| scope o = new Object(); | ||
| scope c = new C(); |
There was a problem hiding this comment.
If the dtor is safe, why wouldn't we allow destruction ?
There was a problem hiding this comment.
I think it's because delete uses a C interface and destroys using TypeInfo.
There was a problem hiding this comment.
But surely at this point, we know the destruction is @safe ?
MartinNowak
left a comment
There was a problem hiding this comment.
Please add a separate error message (e.g. "deleting classes with destructors is unsafe atm.") for the hasDtor case, it seems like an internal limitation of the dmd/druntime API, and it would be very hard for people to understand why their code breaks by adding a dtor.
|
Non-risky bugfixes and in particular all regression fixes should always go into stable. I've changed the target branch to stable, please rebase your PR. |
|
Ping |
|
Something along the line of |
9a21dd6 to
2b1246a
Compare
|
@MartinNowak FYI: I have rebased it and would highly recommend everyone to take similar approach. Wait time on back-and-forth requests for technical trivialities is quite a productivity killer - it is much more practical to make such adjustments directly and move on. |
f44da90 to
43ddb33
Compare
test/fail_compilation/test16195.d
Outdated
| * TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/test16195.d(13): Error: delete p is not @safe but is used in @safe function test | ||
| fail_compilation/test16195.d(13): Error: cannot use 'delete' in @nogc function 'test16195.test' |
There was a problem hiding this comment.
delete is not @nogc ?
There was a problem hiding this comment.
new/delete are part of the gc.
There was a problem hiding this comment.
Makes sense. I was under the impression that it would affect scope class, but it doesn't.
However, the following now compiles with the P.R. (commit 43ddb33):
@safe void dl (int* v) { delete v; }
Which is not the intent of this P.R.
5ce65bc to
66d15ca
Compare
test/fail_compilation/fail14486.d
Outdated
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/fail14486.d(44): Error: delete c0 is not @safe but is used in @safe function test1a | ||
| fail_compilation/fail14486.d(44): Error: cannot use 'delete' in @nogc function 'fail14486.test1a' |
There was a problem hiding this comment.
My comments applied to all the change to the test suite.
void main () @safe
{
auto f = new Object();
delete f;
}Compiles with your P.R., and obviously shouldn't
|
What about the following ? void c () @safe
{
scope o = new Object;
delete o;
auto x = o.toHash();
}I'd suggest we just prohibit explicit destruction of |
|
This definitely requires adding distinction between compiler-injected |
|
@Dicebot yes, I think you're right. But I don't have time to work on this at the moment, it'll have to wait a bit. |
7439d2b to
4ac3fbe
Compare
I explicitly didn't do it, b/c I need Walter to learn how to target the stable branch. It doesn't help if you or I constantly have to rebase PRs from other people. Maybe we should reconsider a few github workflows to make this smoother, but the fact that people already have problems w/ only 2 branches is fairly frustrating. |
|
ping @MartinNowak |
src/expression.h
Outdated
|
|
||
| class DeleteExp : public UnaExp | ||
| { | ||
| bool isRIAA; |
4ac3fbe to
a07034f
Compare
|
FYI @MartinNowak this is the PR we have mentioned yesterday that most likely needs to be moved to scope branch. Please sanity check me. |
|
Why ? It's a regression in 2.072.0. It is valid code which stopped to compile. |
|
It opens an infinite hole in @safe without lifetime checks like ones implememted in scope branch. |
This hole was already there before 2.072.0. What 2.072.0 did was breaking code that could be valid (but could not be verified by the compiler). And breaking valid code is not something we should ever do. |
|
Yes, but thanks for mentioning this anyhow, it's not obvious from the PR and prolly wasn't considered. Disallowing the use of DeleteExp in |
|
Auto-merge toggled on |
|
There is one failing test on OSX (even after repeating it). |
fix Issue 16747 - Cannot have stack allocated classes in @safe code
fix Issue 16747 - Cannot have stack allocated classes in @safe code
Merge pull request #6279 from WalterBright/fix16747
Stack allocated classes with no destructors do not need to call
delete.