The following C code causes a segfault in DMD: typedef enum { SQL_IS_YEAR = 1, SQL_IS_MONTH = 2, SQL_IS_DAY = 3, SQL_IS_HOUR = 4, SQL_IS_MINUTE = 5, SQL_IS_SECOND = 6, SQL_IS_YEAR_TO_MONTH = 7, SQL_IS_DAY_TO_HOUR = 8, SQL_IS_DAY_TO_MINUTE = 9, SQL_IS_DAY_TO_SECOND = 10, SQL_IS_HOUR_TO_MINUTE = 11, SQL_IS_HOUR_TO_SECOND = 12, SQL_IS_MINUTE_TO_SECOND = 13 } SQLINTERVAL; May be a regression of: https://issues.dlang.org/show_bug.cgi?id=22726
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.
(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.
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.
Adam and Bruce have convinced me that there is indeed a need for C to di conversion, so I'll see about addressing this.
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.
*** Issue 24201 has been marked as a duplicate of this issue. ***
@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
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