Initialising Context Pointer during Semantic Analysis

Teodor Dutu teodor.dutu at gmail.com
Fri Nov 25 16:54:24 UTC 2022


On Friday, 25 November 2022 at 16:10:36 UTC, Teodor Dutu wrote:
> `void`-initialising `tmp` from the snippet above is not a 
> solution, as that also leaves the context pointer 
> uninitialised. The code below either seg faults, or prints a 
> random value for `s.y` because the context pointer of `s` is 
> `null`:
>
> ```d
> void main()
> {
>     int x = 3;
>
>     struct S
>     {
>         int y;
>         void bar()
>         {
>             y = x;
>         }
>     }
>
>     S s = void;
>     s.bar();
>
>     writeln(s);
> }
> ```

Also, is it the expected behaviour to leave the context pointer 
uninitalised as well when using `S s = void` or is it a bug? It 
seems odd to not set the context pointer as this makes `S s = 
void` risky to use for nested structs.




More information about the Digitalmars-d mailing list