On 04/15/2012 02:23 PM, Kevin Cox wrote:

On Apr 15, 2012 4:30 AM, "Joseph Rushton Wakeling"
<[email protected] <mailto:[email protected]>> wrote:
 > ... the compiler accepts it.  Whether that's because it's acceptably
pure, or because the compiler just doesn't detect this case of impurity,
is another matter.  The int k is certainly mutable from outside the
scope of the function, so AFAICS it _should_ be disallowed.

As far as I understand pure includes the "hidden this parameter"  so it
is pure if when you call it on the same structure with the same
arguments you always get the same results.  Although that seams pretty
useless in the optimization standpoint

It is useful, because the guarantees it gives still are quite strong. Besides, mutation of the receiver object can be explicitly disabled by marking the method const or immutable; there is no reason why 'pure' should imply 'const'.

because the function can modify
it's own object between calls.


S foo(int a)pure{
    S x;
    x.foo(a);
    x.bar(a);
    return x;
}

Reply via email to