www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22808] New: ImportC: function not decaying to pointer to


          Issue ID: 22808
           Summary: ImportC: function not decaying to pointer to function
                    in return statement.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

The following C code fails to compile:

typedef int(*cmp)(int, int);

int icmp(int a, int b){
    return a < b ? -1 : b < a? 1 : 0;

cmp getcmp(void){
    cmp c;
    c = icmp; // ok
    c = &icmp; // ok
        return c; // ok
        return &icmp; // ok
    return icmp; // Error: cannot implicitly convert expression `icmp` of type
`extern (C) int(int a, int b)` to `extern (C) int function(int, int)`

Feb 21 2022