[Issue 6169] [CTFE] pure functions cannot compute constants using functions not marked as pure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 17 07:02:10 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6169



--- Comment #3 from timon.gehr at gmx.ch 2011-06-17 06:57:25 PDT ---
Interestingly, it does not apply to nothrow unless interpreting the function
fails :). I think this is a diagnostics bug:

int foo(){return 0;}
int bar(){assert(0);}
void main() nothrow{
    enum f = foo(); // fine
    enum b = bar(); // assert(0) failed / bar is not nothrow 
                    // main is nothrow yet may throw
}



(In reply to comment #1)
> ...
> If in future D compilers CTFE will be allowed to modify global variables too,
> then I think your idea is in troubles.
> [snip.]

I think letting CTFE mutate static storage is a bad idea anyways, but actually
that does not matter for this. You are just computing some manifest constant
during compile time that is later used to influence the function's behavior.
This cannot possibly make the function return different results when passed the
same arguments (even during compile time), ergo it is still pure.

> ...
> One problem left is that this proposal introduces another special case in D,
> because the rules of purity have to say a pure function is allowed to call an
> impure one at compile-time. Is it worth it? I think it's acceptable.
> [snip.]

Actually I think this is the same 'special case' as the one that says manifest
constants are evaluated during compile time. The behavior we have now is a
special case of this 'special case'. I think we remove some special casing (and
therefore complexity) by fixing this.

Oh, and this should work too:
string impure(){return ";";}
void main() pure{static s = impure();}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list