#959966 gdc -flto doesn't accept void main() signature.

Package:
gdc
Source:
gcc-defaults
Description:
D compiler (language version 2), based on the GCC backend
Submitter:
Witold Baryluk
Date:
2025-11-28 20:13:03 UTC
Severity:
normal
#959966#5
Date:
2020-05-07 15:16:30 UTC
From:
To:
Dear Maintainer,

According to language spec:

https://dlang.org/spec/function.html#main

"""
19.20 main() Function

For console programs, main() serves as the entry point. It gets called
after all the module initializers are run, and after any unittests are
run. After it returns, all the module destructors are run. main() must be
declared using one of the following forms:

void main() { ... }
void main(string[] args) { ... }
int main() { ... }
int main(string[] args) { ... }
"""


However:
$ cat dlang.d
void main() {
}
$ gdc -flto dlang.d
/usr/lib/gcc/x86_64-linux-gnu/9/include/d/__entrypoint.di:33:5: warning: type of ‘_Dmain’ does not match original declaration [-Wlto-type-mismatch]
   33 | int _Dmain(char[][] args);
      |     ^
dlang.d:2:6: note: type mismatch in parameter 1
    2 | void main() {
      |      ^
dlang.d:2:6: note: type ‘void’ should match type ‘struct char[][]’
dlang.d:2:6: note: ‘D main’ was previously declared here
$

It does compile fine using `int mine(string[] args)` (and returning 0
from it) and run correctly.

Also the message 'void' should match type 'struct char[][]' is confusing.
'struct'? void (return type?) should match it. Weird wording. I guess,
maybe it is parameter 1, which is not in my definition, but should be
string[]. But I am guessing here. Wording is weird and unclear what is
what.

Minor issue, but still a bit annoying and a violatation of the D language
spec.


Regards,
Witold

#959966#10
Date:
2020-05-11 13:52:53 UTC
From:
To:
Internally the last parameter type is 'void' to denote the end of the list (otherwise it's assumed the function is variadic).

Yes, it's a strange message, but this is coming from within the gcc middle-end, and warnings rarely make sense there post lowering.

This was fixed in PR d/90136, which is in gdc-10.

Iain.

#959966#15
Date:
2025-11-28 20:12:05 UTC
From:
To:
Hi Iain,

this looks to have been fixed for few years now.

Can be closed.

Thanks.