Bug 22102 – importC: Error: function is used as a type
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-05T23:08:40Z
Last change time
2021-07-08T06:58:54Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-07-05T23:08:40Z
Reduced test:
---
void test(int *p)
{
}
int main()
{
int array[5];
test(array);
return 0;
}
---
The issue is that the parser can't disambiguate between `type(var)` the declaration and `fncall(var)` the expression.
Comment #1 by ibuclaw — 2021-07-05T23:21:07Z
Similar to issue 21992.
While the rewrite could be handled by DeclarationExp semantic. There's no way to know that the original declaration had parenthesis around the variable name. e.g: If `e.declaration.type` resolves as a function declaration, how do we know whether the original code was `fn(p);` or `fn p;`?
It's probably safer to first assume CallExp in CParser, as that's the most common usage of the ambiguous syntax. If `fn` is then found to be a type, rewrite it into a DeclarationExp.
Comment #2 by dlang-bot — 2021-07-07T23:33:03Z
@ibuclaw created dlang/dmd pull request #12834 "fix Issue 22102 - importC: Error: function is used as a type" fixing this issue:
- fix Issue 22102 - importC: Error: function is used as a type
https://github.com/dlang/dmd/pull/12834
Comment #3 by dlang-bot — 2021-07-08T06:58:54Z
dlang/dmd pull request #12834 "fix Issue 22102 - importC: Error: function is used as a type" was merged into master:
- 56dc76a677315f9bfefeac08c46ed1bf923898d8 by Iain Buclaw:
fix Issue 22102 - importC: Error: function is used as a type
https://github.com/dlang/dmd/pull/12834