Initialising Context Pointer during Semantic Analysis

Teodor Dutu teodor.dutu at gmail.com
Mon Nov 28 17:25:06 UTC 2022


On Saturday, 26 November 2022 at 18:12:44 UTC, Timon Gehr wrote:
> On 11/25/22 17:10, Teodor Dutu wrote:
>> 
>> After discussing with my mentors, we have come up with 2 
>> possible approaches:
>
> Probably the right approach is to lower the call to a local 
> function, e.g., with local template instantiation.
>
> This is a somewhat hacky way to achieve that without changing 
> the compiler frontend:
>
> auto make(T,alias dummy)(){
>     return T(); // can do your emplace magic here
> }
>
> auto foo(){
>     int x=123;
>     struct S{
>         int bar(){ return x; }
>     }
>     void[0] context;
>     return make!(S,context)();
> }
>
>
> void main(){
>     import std.stdio;
>     writeln(foo().bar()); // 123
> }

I don't understand why passing `context` to `make()` is better 
than passing it to `_d_newitemT()` directly. I would still use 
`context` to copy the context pointer, so wouldn't it be the same?




More information about the Digitalmars-d mailing list