D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22831 - No error for malformed extern(C) main function
Summary: No error for malformed extern(C) main function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
: 20377 21503 (view as issue list)
Depends on:
Blocks:
 
Reported: 2022-03-01 17:22 UTC by moonlightsentinel
Modified: 2022-04-13 12:29 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2022-03-01 17:22:27 UTC
DMD silently accepts extern(C) main functions with arbitrary arguments / return type. The spec[1] exlicitly requires one of the following forms:

extern (C) int main() { ... }
extern (C) int main(int argc, char** argv) { ... }

[1] https://dlang.org/spec/function.html#betterc-main
Comment 1 Paul Backus 2022-03-01 17:50:45 UTC
Note that on some platforms there are other possible signatures for main; e.g.,

extern (C) int main(int argc, char** argv, char** envp) { ... }
Comment 2 Dlang Bot 2022-03-03 11:17:40 UTC
@MoonlightSentinel created dlang/dmd pull request #13749 "Fix 22831 - Check signature of extern(C) main functions" fixing this issue:

- Fix 22831 - Check signature of extern(C) main functions
  
  Enforce that the `main` function uses (most likely) valid arguments /
  return types. The spec / C standard denotes the following signatures:
  
  ```d
  int main() { ... }
  int main(int, char**) { ... }
  ```
  
  The implemented checks are more lenient to accomodate for common
  deviations from the standards. See the DDOC comment of `checkMain()`
  for a list of accepted extensions.
  
  Exotic platforms that expect a different signature can circumvent the
  checks using  `pragma(mangle, "main")`.
  
  See e.g. https://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function

https://github.com/dlang/dmd/pull/13749
Comment 3 Dlang Bot 2022-03-23 12:41:10 UTC
dlang/dmd pull request #13749 "Fix 22831 - Check signature of extern(C) main functions" was merged into master:

- 118e246c5162e81cd49a8a785ebe0cec9957f360 by MoonlightSentinel:
  Fix 22831 - Check signature of extern(C) main functions
  
  Enforce that the `main` function uses (most likely) valid arguments /
  return types. The spec / C standard denotes the following signatures:
  
  ```d
  int main() { ... }
  int main(int, char**) { ... }
  ```
  
  The implemented checks are more lenient to accomodate for common
  deviations from the standards. See the DDOC comment of `checkMain()`
  for a list of accepted extensions.
  
  Exotic platforms that expect a different signature can circumvent the
  checks using  `pragma(mangle, "main")`.
  
  See e.g. https://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function

https://github.com/dlang/dmd/pull/13749
Comment 4 moonlightsentinel 2022-03-29 18:34:01 UTC
*** Issue 20377 has been marked as a duplicate of this issue. ***
Comment 5 Dennis 2022-04-13 12:29:31 UTC
*** Issue 21503 has been marked as a duplicate of this issue. ***