Inferring Purity Woes

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon May 18 06:23:04 PDT 2015


On 5/15/15 10:30 PM, Xinok wrote:
> I've been avoiding purity in D for a while but I decided to take a stab
> at it today. I encountered two issues which make inferring purity
> difficult.
>
>
> (1) While the compiler infers purity for instantiated functions, it's
> unable to infer purity for "functions within templates". Consider the
> following three statements:
>
> void foo()(){ }
> template T(){  void foo()(){ }  }
> template T(){  void foo(){ }  }
>
> The compiler can infer purity for the first two statements but not the
> third. So even though the functions are within a template, you still
> have to make each individual function an "instantiated function" in
> order to infer purity for them.

This is a bug I think. functions that are part of templates should be 
inferred. It works for structs, e.g.:

struct S()
{
    void foo() {}
}

void main() pure
{
    S!().init.foo();
}

-Steve


More information about the Digitalmars-d mailing list