[Issue 2807] New: Marking a nested function as 'pure' may cause bad code generations silently accepted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 6 06:03:30 PDT 2009


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

           Summary: Marking a nested function as 'pure' may cause bad code
                    generations silently accepted
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: clugdbug at yahoo.com.au


The following assert fails, effectively generating bad code.
My patch in #2804 doesn't fix this, but it does reduce the need for marking
nested functions as pure. A nested function which is marked as pure should not
be able to access variables from the enclosing scope.
It's probably adequate to simply disallow 'pure' on nested functions for now.

---
pure int double_sqr(int x) {
    int y = x;
    void do_sqr() pure { y *= y; }
    do_sqr();
    return y;
}

void main(string[] args) {
   assert(double_sqr(10) == 100);
}


-- 



More information about the Digitalmars-d-bugs mailing list