www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - bug in purity validation

reply Timon Gehr <timon.gehr gmx.ch> writes:
From bearophile's ported benchmark:

    // Getters/Setters
    pure nothrow SimpleLoop* parent() { return parent_; }
    //...
    pure nothrow void setParent(SimpleLoop* parent) {
        parent_ = parent;
        parent.addChildLoop(&this);
    }
    //...
    SimpleLoop* parent_;

Why does that compile? There is no way those functions can be pure.

Timon
Jun 05 2011
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
Timon Gehr wrote:
 From bearophile's ported benchmark:

     // Getters/Setters
     pure nothrow SimpleLoop* parent() { return parent_; }
     //...
     pure nothrow void setParent(SimpleLoop* parent) {
         parent_ = parent;
         parent.addChildLoop(&this);
     }
     //...
     SimpleLoop* parent_;

 Why does that compile? There is no way those functions can be pure.

 Timon
Ah, the implicit "this" parameter... Timon
Jun 05 2011
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 05/06/2011 11:10, Timon Gehr wrote:
<snip>
 Ah, the implicit "this" parameter...
What's that to do with anything? Stewart.
Jun 11 2011
parent Timon Gehr <timon.gehr gmx.ch> writes:
Stewart Gordon wrote:
 On 05/06/2011 11:10, Timon Gehr wrote:
 <snip>
 Ah, the implicit "this" parameter...
What's that to do with anything? Stewart.
I weakly pure function may modify any memory location reachable by its (mutable) parameters. What I didn't realize at first and late in the night is that obviously this also applies to the implicit 'this' parameter. Timon
Jun 11 2011