Thread overview
[Issue 24121] ImportC: typedef enum fails to compile when generating .di file
[Issue 24121] ImportC: typedef enum fails to compile
Sep 01, 2023
Rory
Sep 02, 2023
Adam Wilson
Sep 11, 2023
Walter Bright
Sep 12, 2023
Walter Bright
Oct 25, 2023
Walter Bright
Oct 25, 2023
Walter Bright
Oct 27, 2023
Walter Bright
Oct 27, 2023
Dlang Bot
Oct 27, 2023
Dlang Bot
September 01, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

Rory <rjmcguire@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rjmcguire@gmail.com

--- Comment #1 from Rory <rjmcguire@gmail.com> ---
I came here to report a similar issue with typedef enums but my code now works. I tried the enum posted here and the code compiles fine for me.

Do you know which version of DMD this segfault was in?

I'm using linux DMD64 D Compiler v2.105.0.

--
September 02, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

--- Comment #2 from Adam Wilson <flyboynw@gmail.com> ---
(In reply to Rory from comment #1)
> I came here to report a similar issue with typedef enums but my code now works. I tried the enum posted here and the code compiles fine for me.
> 
> Do you know which version of DMD this segfault was in?
> 
> I'm using linux DMD64 D Compiler v2.105.0.

I am using Windows DMD64 2.105 and I just verified the segfault.

The commandline used is: dmd sql.i -Hf=sql.di -verrors=0 -main

If I remove the -Hf=sql.di switch then it works.

--
September 11, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ImportC: typedef enum fails |ImportC: typedef enum fails
                   |to compile                  |to compile when generating
                   |                            |.di file

--
September 12, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
The problem is that C code is not always representable as D code. D doesn't have anonymous enum types, for example, which I'm pretty sure is the cause of the seg fault.

One reason for ImportC is it enables the D compiler to accommodate exact C semantics. The D compiler can import a C file, and use its declarations directly. If the C file was converted to a .di file, then the D compiler can import the .di file and use its declarations directly.

Consequently, there should be no need to covert a C file to a .di file.

--
October 25, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
Adam and Bruce have convinced me that there is indeed a need for C to di conversion, so I'll see about addressing this.

--
October 25, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
Currently, the .i file:

typedef enum
{
    SQL_IS_YEAR  = 1,
    SQL_IS_MONTH = 2
} SQLINTERVAL;


produces a .di file:

// D import file generated from 'test.i'
extern (C)
{
        align enum SQLINTERVAL
        {
                SQL_IS_YEAR = 1,
                SQL_IS_MONTH = 2,
        }
        alias SQLINTERVAL = enum SQLINTERVAL;
}

which is just wrong.

--
October 27, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dave287091@gmail.com

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---
*** Issue 24201 has been marked as a duplicate of this issue. ***

--
October 27, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #15736 "fix Issue 24121 - ImportC: typedef enum fails to compile when generat…" fixing this issue:

- fix Issue 24121 - ImportC: typedef enum fails to compile when generating .di file

https://github.com/dlang/dmd/pull/15736

--
October 27, 2023
https://issues.dlang.org/show_bug.cgi?id=24121

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #15736 "fix Issue 24121 - ImportC: typedef enum fails to compile when generat…" was merged into master:

- 7a3ae70494706f49aa8b54f8752d3f2444523a41 by Walter Bright:
  fix Issue 24121 - ImportC: typedef enum fails to compile when generating .di
file

https://github.com/dlang/dmd/pull/15736

--