D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11286 - Impure dtor makes "cannot call impure function" error, although it won't actually be called.
Summary: Impure dtor makes "cannot call impure function" error, although it won't actu...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-10-17 01:36 UTC by Kenji Hara
Modified: 2013-11-07 20:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2013-10-17 01:36:48 UTC
From: http://forum.dlang.org/thread/wqxziknnhlyoyetwmtyu@forum.dlang.org
=====================================

I get this error:
----
/d701/f223.d(11): Error: pure function 'f223.getA' cannot call 
impure function 'f223.A.~this'
----

with this code:
----
import std.stdio;

struct A {
public:
    ~this() {
        writeln("DTor");
    }
}

A getA() pure nothrow {
    return A();
}

void main()
{
    A a = getA();
	
    writeln("end of main");
}
----

But without pure and nothrow I get this output:
----
end of main
DTor
----

Why the compiler thinks that the function should/could call 
A::~this?
Comment 2 github-bugzilla 2013-11-07 20:08:05 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/8d2ac819d9c71951e1adabaf0ce1c0e5073d8e91
fix Issue 11286 - Impure dtor makes "cannot call impure function" error, although it won't actually be called.

https://github.com/D-Programming-Language/dmd/commit/d9a2adb1bda4fa146ed3aa4acbce45c6be1ffdc0
Merge pull request #2677 from 9rnsr/fix11286

Issue 11286 - Impure dtor makes "cannot call impure function" error, although it won't actually be called.