[Issue 8204] Can't instantiate auto ref template explicitly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 28 10:58:35 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=8204

vitamin <submada at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |submada at gmail.com

--- Comment #10 from vitamin <submada at gmail.com> ---
This problem has become worst. 

`auto ref` inference is no longer only problem. `scope` and `return` parameter
storage classes inference has similar problem.

Example how inference differ from manual template instantion:
```d  
void foo(T)(T* ptr){
}

ref T bar(T)(ref T val){
    static if(is(T == long))
        return *new T(val);
    else 
        return val;
}


static long* global_ptr;

void main()@safe{

    {
        //void function(int* ptr) pure nothrow @nogc @safe:
        pragma(msg, typeof(&foo!int));  

        //void function(int* ptr) pure nothrow @nogc @safe:
        foo(new int);                                   
    }

    {
        //void function(int* ptr) pure nothrow @nogc @safe:
        pragma(msg, typeof(&foo!int));  

        //void function(scope int* ptr) pure nothrow @nogc @safe:
        scope int* i;
        foo(i);                                         
    }

    {
        //int function(ref int val) pure nothrow @nogc ref @safe:
        pragma(msg, typeof(&bar!int));  

        //int function(return ref int val) pure nothrow @nogc ref @safe:
        scope int x;
        scope int* ptr = &bar(x);       
    }
    {
        //long function(ref long val) pure nothrow ref @safe:
        pragma(msg, typeof(&bar!long));

        //long function(scope ref long val) pure nothrow ref @safe:
        scope long x;
        global_ptr = &bar(x);                   
    }
}
```

--


More information about the Digitalmars-d-bugs mailing list