This compiles, and it shouldn't. Interestingly, if you replace 'pure' with 'nothrow', the code is correctly rejected.
--------
static int nasty;
int impure_evil_function(int x)
{
nasty++;
return nasty;
}
pure int foo(int x)
{
int function(int) a = &impure_evil_function;
return a(x);
}
--------
Comment #1 by clugdbug — 2009-04-22T03:30:44Z
Created attachment 334
Patch for DMD2.029.
This patch also prevents pure functions from calling impure delegates.
It (correctly) does not prevent them from assigning to impure function pointers/delegates -- it just mustn't call them. I've tested it with delegates/functions passed as parameters, as well as defined as variables; I've also tested it with template functions, and with structs defining opCall, and made sure it doesn't cause problems with variables defined in module scope.