[Issue 23579] static locals cannot be initialized with stack locals
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Dec 27 23:47:19 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23579
Iain Buclaw <ibuclaw at gdcproject.org> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3
                 CC|                            |ibuclaw at gdcproject.org
--- Comment #4 from Iain Buclaw <ibuclaw at 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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list