May 07, 2017 [Issue 17376] New: modify global variable with pure method | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17376 Issue ID: 17376 Summary: modify global variable with pure method Product: D Version: D2 Hardware: x86 OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: arbmind@gmail.com Consider this test code: int ga; struct Tester { int* pa; this(int) { pa = &ga; } void test() pure { *pa = 3; } } void main() { auto t = Tester(1); assert(ga == 0); t.test(); assert(ga == 3); } >From the perspective of the caller, he is calling a pure function, but can observe a global state change. It is also possible to change a static member of the struct in the same manner. I guess that this inhibits some opportunities for optimizations. -- |
Copyright © 1999-2021 by the D Language Foundation