Just tried building the Mosquitto MQTT library (specifically just the client library) on Artix Linux x64 solely with DMD master. I tried the following:
cd lib
dmd-master -P=-I../ -P=-I../deps *.c
...and got some errors on every mention of assert(). Try just one file to see what I mean:
dmd-master -P=-I../ -P=-I../deps messages_mosq.c
messages_mosq.c(52): Error: expression expected, not `{`
messages_mosq.c(52): Error: found `if` when expecting `)`
messages_mosq.c(52): Error: found `;` when expecting `)`
messages_mosq.c(52): Error: found `else` when expecting `;` following statement
messages_mosq.c(52): Error: no type for declarator before `)`
messages_mosq.c(54): Error: no type for declarator before `for`
messages_mosq.c(54): Error: no type for declarator before `(`
messages_mosq.c(54): Error: no type for declarator before `(`
messages_mosq.c(56): Error: no type-specifier for declarator
messages_mosq.c(56): Error: found `;` when expecting `)`
messages_mosq.c(57): Error: `=`, `;` or `,` expected to end declaration instead of `}`
messages_mosq.c(58): Error: no type for declarator before `(`
messages_mosq.c(58): Error: no type for declarator before `(`
messages_mosq.c(60): Error: no type-specifier for declarator
messages_mosq.c(60): Error: found `;` when expecting `)`
messages_mosq.c(61): Error: `=`, `;` or `,` expected to end declaration instead of `}`
messages_mosq.c(68): Error: no type-specifier for declarator
messages_mosq.c(69): Error: no type-specifier for declarator
messages_mosq.c(70): Error: no type for declarator before `if`
messages_mosq.c(71): Error: no type-specifier for declarator
If I comment out all uses of assert() (including in deps/utlist.h), I get similar errors from the use of the DL_DELETE macro in deps/utlist.h:
messages_mosq.c(154): Error: found `else` when expecting `while`
messages_mosq.c(154): Error: found `{` when expecting `(`
messages_mosq.c(157): Error: found `;` when expecting `)`
messages_mosq.c(158): Error: found `}` when expecting `;` following terminating `;` required after do-while statement
messages_mosq.c(193): Error: `=`, `;` or `,` expected to end declaration instead of `{`
messages_mosq.c(246): Error: found `}` when expecting `while`
messages_mosq.c(247): Error: found `;` when expecting `(`
messages_mosq.c(248): Error: expression expected, not `if`
messages_mosq.c(248): Error: found `{` when expecting `)`
messages_mosq.c(249): Error: found `return` when expecting `;` following terminating `;` required after do-while statement
messages_mosq.c(249): Error: type-specifier missing for declaration of `MOSQ_ERR_SUCCESS`
messages_mosq.c(253): Error: found `else` without a corresponding `if` statement
messages_mosq.c(267): Error: found `}` when expecting `while`
messages_mosq.c(269): Error: found `;` when expecting `(`
messages_mosq.c(270): Error: expression expected, not `if`
messages_mosq.c(270): Error: found `{` when expecting `)`
messages_mosq.c(271): Error: found `return` when expecting `;` following terminating `;` required after do-while statement
messages_mosq.c(271): Error: type-specifier missing for declaration of `MOSQ_ERR_SUCCESS`
messages_mosq.c(279): Error: `=`, `;` or `,` expected to end declaration instead of `{`
Wondering what the deal is here...
Comment #2 by krzysztof.jajesnica — 2023-01-12T11:27:39Z
I accidentally hit the same bug while trying to compile the Nuklear library with DMD 2.101.1 on Manjaro Linux.
Based on the error message and source code of assert.h I think ImportC is trying to use the following definition of assert:
# define assert(expr) \
((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \
if (expr) \
; /* empty */ \
else \
__assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \
}))
The problem seems to be caused by 2 GCC extensions used in the assert macro which are not supported by ImportC:
1. Statement expressions (https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html)
(basically GCC treats code like this: ({statement1; statement2;}) as an expression)
2. __PRETTY_FUNCTION__ - this one is hidden inside the __ASSERT_FUNCTION macro
Comment #3 by dkorpel — 2023-02-28T11:23:42Z
I also stumbled on this when trying to compile the tree-sitter run time library.
Comment #4 by bugzilla — 2023-04-09T07:15:04Z
Might be able to support statement expressions by converting them to a nested function with no arguments.
This won't work, though, with jumping into or out of a statement expression.
Comment #5 by bugzilla — 2023-04-09T07:18:48Z
*** Issue 23619 has been marked as a duplicate of this issue. ***
Comment #6 by dlang-bot — 2023-04-10T01:54:37Z
@WalterBright created dlang/dmd pull request #15093 "fix Issue 23509 - ImportC: need statement expressions extension" fixing this issue:
- fix Issue 23509 - ImportC: need statement expressions extension for GLibC's assert()
https://github.com/dlang/dmd/pull/15093
Comment #7 by dlang-bot — 2023-04-10T17:36:03Z
dlang/dmd pull request #15093 "fix Issue 23509 - ImportC: need statement expressions extension" was merged into master:
- a2e50cdbdcb4749c6198d06365054a5a292b4a0c by Walter Bright:
fix Issue 23509 - ImportC: need statement expressions extension for GLibC's assert()
https://github.com/dlang/dmd/pull/15093