www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20962] New: Template parameter evaluating to D style array

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

          Issue ID: 20962
           Summary: Template parameter evaluating to D style array
                    prevents implicit conversion of function literal to
                    extern(C++)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: cristiancreteanu06 gmail.com

extern (C++) class A
{
        __gshared void function() func;
}

__gshared extern (C++) void function() anotherFunc;

void foo(T)(T bar)
{
    A.func = function void() {};
    anotherFunc = function void() {};    
}

void main()
{
    int[] arr;
    foo(arr);
}



The code above fails with the following error:

Error: Internal Compiler Error: type int[] cannot be mapped to C++


It acts as if the argument, which was evaluated to a D array, was passed inside
the function assigned to the pointer declared as extern(C++), which is not the
case. The error does not occur if I change the foo function by removing the
template parameter and defining it as follows:

void foo(int[] bar)
{
    A.func = function void() {};
    anotherFunc = function void() {};    
}

--
Jun 20 2020