[Issue 4031] New: Tidier management of static variables in pure functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 30 03:00:45 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4031
Summary: Tidier management of static variables in pure
functions
Product: D
Version: future
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid, 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-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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list