digitalmars.D - bug in purity validation
- Timon Gehr <timon.gehr gmx.ch> Jun 05 2011
- Timon Gehr <timon.gehr gmx.ch> Jun 05 2011
- Stewart Gordon <smjg_1998 yahoo.com> Jun 11 2011
- Timon Gehr <timon.gehr gmx.ch> Jun 11 2011
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
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
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
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








Timon Gehr <timon.gehr gmx.ch>