[Issue 15862] dmd thinks functions are strongly pure despite mutable indirections in the return type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 3 15:38:20 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15862

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from ag0aep6g at gmail.com ---
(In reply to Walter Bright from comment #2)
> This is as designed and intended.
> 
> 1. Mutable indirections in the return type do not affect purity
> determination. Mutability of the parameters does.

Sorry, but this is ridiculous. Reopening. Please explain how on earth the shown
behavior is supposedly acceptable.

> 2. An early design decision was that calling new() inside a pure function is
> an acceptable special case. (Otherwise pure functions would be nearly
> useless.)

This is fine. It follows that the compiler must not consider the result
reusable when a function has a mutable indirection in the return type, even
when it's otherwise pure. A strongly pure function (with const parameters) can
only return an int* by newly allocating it. And then reusing it is disastrous.

--


More information about the Digitalmars-d-bugs mailing list