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

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; }
    return y;

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


Reply via email to