[Issue 8637] Enforcement and purity

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 10 08:13:36 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8637


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2


--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2012-09-10 08:14:02 PDT ---
(In reply to comment #0)
> The argument taken by enforce must be "castable to bool", so the the
> implementation can do the cast. However, enforce is declared pure, so if the
> cast operator is not pure, the compilation fails:
[snip]
> --------
> Error: pure function 'enforce' cannot call impure function '~this'
> Error: pure function 'enforce' cannot call impure function 'opCast'
> --------

The cause might be the explicit annotation with pure.

> The messages come from:
> 
> --------
> T enforce(T)(T value, lazy const(char)[] msg = null, string file = __FILE__,
> size_t line = __LINE__) @safe pure
> {
>     if (!value) bailOut(file, line, msg);
>     return value;
> }
> --------
> "if(!value)": This makes an impure call to opCast.
> 
> "enforce(T)(T value..." This uses pass by value, and makes an impure call to
> the destructor
>
> I have no idea what a good fix would be. Regarding pass by value, wouldn't this
> be a textbook example of using "auto ref" with "auto return"? I have no idea...

The strict pure annotation is introduced by the pull #263.
https://github.com/D-Programming-Language/phobos/pull/263

As you can see, the pure annotations were just for the documentation. At this
point, impure destructor had not been considered at all in the discussion.

Then, now, the pure annotation causes this problem, so I think we should remove
it and rely on the pure attribute inference.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list