[Issue 20962] New: Template parameter evaluating to D style array prevents implicit conversion of function literal to extern(C++)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 20 15:13:14 UTC 2020


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 at puremagic.com
          Reporter: cristiancreteanu06 at 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() {};    
}

--


More information about the Digitalmars-d-bugs mailing list