Basically, if you call a function "UFCS style", on an object that has an alias this, then the compiler (from what I can observe) will consider the "alias this" as "called" to evaluate the attributes, even if the alias this is not actually called. Example:
//----
void foo(T)(ref T t)
{
pragma(msg, T.stringof);
}
struct S
{
int impure() {assert(0);}
alias impure this;
}
void main() pure
{
S s;
foo(s); //YES
s.foo(); //NO
}
//----
Error: pure function 'D main' cannot call impure function 'main.S.impure'
//----
What's "funny" is that is you remove the "pure" on main, we can verify that "impure" is never actually called.
Discovered while writing:
https://github.com/D-Programming-Language/phobos/pull/2202
Originally:
assert(!source.doesPointTo(source), "msg");
Worked around with:
assert(!doesPointTo(source, source), "msg");
Comment #1 by github-bugzilla — 2018-04-23T07:55:39Z