Summary: Tidier management of static variables in pure
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-03-30 03:00:41 PDT ---
Here I propose two small different changes: to refuse line 2 and accept line 4.

Mutable static variables can't be used in pure functions, so it's better to
really disallow them, and produce a compile error at line 2 here (there's no
point in allowing their definition and disallowing just their usage).

(On the other hand the static "z" at line 3 is a const and can be allowed, as
dmd does now.)

The compiler can also allow the line 4, because z will not change, keeping the
function foo pure (there is no point in disallowing something that's
semantically correct and safe).

pure int foo(int x) {
    static int y = 10;       // line 2  ERR
    const static int z = 20; // line 3  OK (as now)
    return x + z;            // line 4  OK
void main() {}

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to