Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 26, 2022 [Issue 23579] static locals cannot be initialized with stack locals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23579 Nick Treleaven <nick@geany.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nick@geany.org --- Comment #1 from Nick Treleaven <nick@geany.org> --- Assignment is not initialization. A static variable is only initialised once. What is your use case? In the example b's previous value is discarded every time v is called, so why is b static? -- |
December 26, 2022 [Issue 23579] static locals cannot be initialized with stack locals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23579 --- Comment #2 from Basile-z <b2.temp@gmx.com> --- I have no use case, it's just something that I've noticed and that I find odd. -- |
December 26, 2022 [Issue 23579] static locals cannot be initialized with stack locals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23579 Max Samukha <maxsamukha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxsamukha@gmail.com --- Comment #3 from Max Samukha <maxsamukha@gmail.com> --- (In reply to Nick Treleaven from comment #1) > Assignment is not initialization. A static variable is only initialised once. What is your use case? In the example b's previous value is discarded every time v is called, so why is b static? The initialization vs assignment distinction is useless, given the requirement that T.init is a valid value of T. -- |
December 27, 2022 [Issue 23579] static locals cannot be initialized with stack locals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23579 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P3 CC| |ibuclaw@gdcproject.org --- Comment #4 from Iain Buclaw <ibuclaw@gdcproject.org> --- C++ supports and implements this by generating the following code: ``` void v(int a) { static bool __guard_for_b = false; static int b = 0; if (__guard_for_b == 0) { b = a; __guard_for_b = true; } } ``` Things get hairier with __gshared variables. ``` void v(int a) { __gshared bool __guard_for_b = false; __gshared int b = 0; if (core.atomic.atomicLoad!(MemoryOrder.acq)(__guard_for_b) == 0) { synchronized // __cxa_guard_acquire(&__guard_for_b) { b = a; __guard_for_b = true; } // __cxa_guard_release(&__guard_for_b) } } ``` I don't think we really need such an expensive run-time feature in D. -- |
July 14, 2023 [Issue 23579] static locals cannot be initialized with stack locals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23579 Basile-z <b2.temp@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |WONTFIX -- |
Copyright © 1999-2021 by the D Language Foundation