dmd 2.039 doesn't produce error for pure function with auto return type that violates purity: int global; pure auto f() { global = 1; return 0; } compiles without errors.
Actually, the bug is something different: pure auto f() { return 0; } pure int g() { return f(); } bug.d(3): Error: pure function 'g' cannot call impure function 'f' The bug is that for 'auto' functions, 'pure' is ignored. Bug 3359 is another aspect of the same thing. In fact I think there are about five bugs which probably all have the same root cause.
This patch also fixes bug 4640, bug 5006, and cases 2 and 3 of bug 3573. PATCH: func.c, FuncDeclaration::semantic, line 164. All of the function-related storage classes need to be applied to the function. (Possibly STCsynchronised as well? Maybe there should be a #define which puts all of these together, in case the relevant list gets longer). if (!type->deco) { sc = sc->push(); - sc->stc |= storage_class & STCref; // forward to function type + sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCdisable | STCproperty | STCsafe | STCtrusted | STCsystem); // forward to function type if (isCtorDeclaration()) sc->flags |= SCOPEctor;
Test case (should compile with no errors): pure nothrow @safe auto bug4915a() { return 0; } pure nothrow @safe int bug4915b() { return bug4915a(); } void bug4915c() { pure nothrow @safe int d() { return 0; } int e() pure nothrow @safe { return d(); } }
oops, STCproperty shouldn't be in that list.
http://www.dsource.org/projects/dmd/changeset/748