Bug 22342 – importC: Error: function 'func()' is not callable using argument types '(int)'

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-09-28T17:44:17Z
Last change time
2021-10-08T09:37:32Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
See also
https://issues.dlang.org/show_bug.cgi?id=22343, https://issues.dlang.org/show_bug.cgi?id=22344

Comments

Comment #0 by ibuclaw — 2021-09-28T17:44:17Z
In C11, having an empty parentheses `()` is equivalent to D `(...)`, and so the following should not error. --- void func() { } int main() { func(12); func("12"); func(1.2); return 0; } --- The correct code in order to induce the error we want is to use `(void)` --- void func(void) { } int main() { func(12); // error: too many arguments func("12"); // error: too many arguments func(1.2); // error: too many arguments return 0; } ---
Comment #1 by ibuclaw — 2021-09-28T22:23:25Z
C11 6.7.6.3-14: An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied(*). (*) See "future language directions" (6.11.6). C11 6.11.6: The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.
Comment #2 by ibuclaw — 2021-10-03T17:13:35Z
Side effects cannot be discarded either: --- int printf(const char *, ...); int foo() { printf("A\n"); return 0; } int bar() { printf("B\n"); return 0; } int main() { int v; return bar(1, &v, foo(), "str", bar()); } --- Compiles without any warnings, and outputs: --- B A B
Comment #3 by ibuclaw — 2021-10-03T17:16:18Z
(In reply to Iain Buclaw from comment #2) > Side effects cannot be discarded either: void expressions passed as a parameter are an error though.
Comment #4 by dlang-bot — 2021-10-06T08:38:36Z
@WalterBright created dlang/dmd pull request #13132 "fix Issue 22342 - importC: Error: function 'func()' is not callable u…" fixing this issue: - fix Issue 22342 - importC: Error: function 'func()' is not callable using argument types '(int) https://github.com/dlang/dmd/pull/13132
Comment #5 by dlang-bot — 2021-10-07T15:38:55Z
dlang/dmd pull request #13132 "fix Issue 22342 - importC: Error: function 'func()' is not callable u…" was merged into master: - 93a744d20e5989b324b437ed91374b8270cedf26 by Walter Bright: fix Issue 22342 - importC: Error: function 'func()' is not callable using argument types '(int) https://github.com/dlang/dmd/pull/13132