www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23363] New: ImportC: Enums contain wrong members


          Issue ID: 23363
           Summary: ImportC: Enums contain wrong members
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: ImportC
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kipthemudkip yahoo.com

It appears enum types from ImportC modules don't pick up members from the
actual type, but take them from global #defines who knows where. To see what I
mean, create a similar setup:

#include <git2.h>

import git2;

alias DumpModuleEnums(alias someModule) = () {
  static foreach (memberName; __traits(allMembers, someModule)) {{
    alias member = __traits(getMember, git2, memberName);
    static if (is(member == enum)) {
      pragma(msg, memberName);
      static foreach (enumMemberName; __traits(allMembers, member)) {
        pragma(msg, "    ", enumMemberName);

alias dumpGit2 = DumpModuleEnums!git2;

On my x64 Linux Mint machine, many of the enums look like:


What are these mysterious members? They seem to be taken from

/* First argument to waitid: */
#define P_ALL           0
#define P_PID           1
#define P_PGID          2
#define P_PIDFD         3

Very bizarre!!

Sep 23 2022