Bug 24042 – ImportC: Error: no definition for static function

Status
REOPENED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-07-09T19:57:23Z
Last change time
2024-12-13T19:30:07Z
Keywords
diagnostic, ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#18180 →

Comments

Comment #0 by ibuclaw — 2023-07-09T19:57:23Z
``` // cfile.c static int staticfunc() { return 0; } // dmodule.d import cfile; int main() { return staticfunc(); } ``` Compiler IMO correctly issues an error --- Error: no definition for static staticfunc --- However, besides the obvious lack of source file/line information, it looks like the error occurs (in the back-end) because the symbol is missing from compilation, rather than just disallowing the referencing of C static symbols from D. Even if both D and C sources are compiled in the same CU, I find it questionable to allow referencing C static symbols from D. But that can be debated out here. For reference, this is where in dmd backend the error comes from. ``` // In backend/cgen.d if (f.sym.Sseg == UNKNOWN) { printf("Error: no definition for static %s\n", prettyident(f.sym)); // no definition found for static err_exit(); // BUG: do better } ```
Comment #1 by bugzilla — 2023-11-23T04:32:59Z
Unfortunately, the backend Symbol does not include file/line info. It would be expensive to add it for just this case.
Comment #2 by dlang-bot — 2023-11-23T04:43:55Z
@WalterBright created dlang/dmd pull request #15855 "fix Issue 24042 - ImportC: Error: no definition for static function" fixing this issue: - fix Issue 24042 - ImportC: Error: no definition for static function https://github.com/dlang/dmd/pull/15855
Comment #3 by dlang-bot — 2023-11-23T08:14:32Z
@WalterBright updated dlang/dmd pull request #15856 "fix Issue 24031 - ImportC: rejects nested C initializers" fixing this issue: - fix Issue 24042 - ImportC: Error: no definition for static function https://github.com/dlang/dmd/pull/15856
Comment #4 by dlang-bot — 2023-11-23T08:18:38Z
@WalterBright created dlang/dmd pull request #15857 "fix Issue 24042 - ImportC: Error: no definition for static function" fixing this issue: - fix Issue 24042 - ImportC: Error: no definition for static function https://github.com/dlang/dmd/pull/15857
Comment #5 by dlang-bot — 2023-11-24T08:42:27Z
dlang/dmd pull request #15857 "fix Issue 24042 - ImportC: Error: no definition for static function" was merged into master: - 256e74d01e0b75918b2d4f6d566a9b847ba36c76 by Walter Bright: fix Issue 24042 - ImportC: Error: no definition for static function https://github.com/dlang/dmd/pull/15857
Comment #6 by dkorpel — 2023-11-24T08:42:56Z
Re-opening, linked PR didn't add requested front-end check: https://github.com/dlang/dmd/pull/15857#issuecomment-1825185778
Comment #7 by ibuclaw — 2023-11-24T18:25:23Z
(In reply to Walter Bright from comment #1) > Unfortunately, the backend Symbol does not include file/line info. It would > be expensive to add it for just this case. Isn't the line info just a ushort now?
Comment #8 by robert.schadek — 2024-12-13T19:30:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18180 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB