D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17505 - [REG2.075] @safe constructor requires the deconstructor to be safe as well
Summary: [REG2.075] @safe constructor requires the deconstructor to be safe as well
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-15 00:20 UTC by Seb
Modified: 2017-08-07 13:16 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Seb 2017-06-15 00:20:53 UTC
cat > main.d << CODE
struct Array
{
    int[] _payload;
    ~this()
    {
        import core.stdc.stdlib : free;
        free(_payload.ptr);
    }
}

class Scanner
{
    Array arr;
    this() @safe {}
}
CODE


$ dmd -main

main.d(14): Error: @safe constructor 'main.Scanner.this' cannot call @system destructor 'main.Scanner.~this'
Comment 1 Martin Nowak 2017-06-17 03:12:46 UTC
Introduced by https://github.com/dlang/dmd/pull/6816

Also manifestates in libasync https://github.com/etcimon/libasync/blob/a56cf33720731de717ef5d6c5f1c0d51341da145/source/libasync/events.d#L57.

----
source/libasync/events.d(57,2): Error: destructor 'libasync.events.EventLoop.~this' is not nothrow
source/libasync/events.d(57,2): Error: nothrow constructor 'libasync.events.EventLoop.this' may throw
----
Comment 2 Seb 2017-06-17 03:19:21 UTC
FYI have you seen Cybershadow's comment?
https://github.com/dlang/dmd/pull/6816#issuecomment-307657520

And his reduced test case for the regression in libasync?

struct S
{
    ~this() {}
}

class C
{
    S s;

    this() nothrow {}
}
Comment 3 Martin Nowak 2017-06-17 08:32:44 UTC
(In reply to greenify from comment #2)
> FYI have you seen Cybershadow's comment?
> https://github.com/dlang/dmd/pull/6816#issuecomment-307657520

Ah thanks, libasync is a duplicate of issue 17494, does have the nothrow, not the `@safe` issue.
Comment 4 github-bugzilla 2017-06-17 10:16:17 UTC
Commit pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/558773e64d42d56ad02970adfdc1371311ca3291
add test cases for existing production code

- fixes Issues 17494, 17505, 17506
Comment 5 github-bugzilla 2017-08-07 13:16:48 UTC
Commit pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/558773e64d42d56ad02970adfdc1371311ca3291
add test cases for existing production code