[Issue 4177] New: __ctfe can't be used in pure functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 12 04:09:08 PDT 2010


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

           Summary: __ctfe can't be used in pure functions
           Product: D
           Version: future
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-05-12 04:09:05 PDT ---
To define a std.math.log() function that works at compile time (see bug 3749 )
it can be used __ctfe, but there are problems:


pure real log(real x) {
    if (__ctfe)
        return 0.0;
    else
        return 1.0;
}
enum x = log(4.0);
void main() {}


dmd v2.045 prints:

test.d(2): Error: variable __ctfe forward referenced
test.d(2): Error: pure nested function 'log' cannot access mutable data
'__ctfe'
test.d(7): Error: cannot evaluate log(4L) at compile time
test.d(7): Error: cannot evaluate log(4L) at compile time


I'd like __ctfe to work in pure functions too.
I think it can be done because it's an immutable value that I think can't break
the purity of the function/method, even if as in that example the function can
give different outouts at compile and run time.

-- 
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