www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22665] New: ImportC: enums are not "implicitly converting" to

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

          Issue ID: 22665
           Summary: ImportC: enums are not "implicitly converting" to
                    their own type.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

Consider the following:
// an_enum.c
enum AnEnum {
    A = 0,
    B = 1,
};

// use_an_enum.d
import an_enum;

int foo(AnEnum e){
    AnEnum ae = AnEnum.A; // Error: cannot implicitly convert expression `0` of
type `int` to `AnEnum`
    switch(e){
        case AnEnum.A: // Error: cannot implicitly convert expression `0` of
type `int` to `AnEnum`
            return 1;
        case AnEnum.B: // Error: cannot implicitly convert expression `1` of
type `int` to `AnEnum`
            return 2;
    }
}

As one of the major benefits of ImportC is getting access to enums defined in
C, this is a major problem.

--
Jan 11 2022