Bug 22182 – importC: Error: expression expected, not `)` when casting pointer with redundant parens.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-05T21:38:08Z
Last change time
2021-08-10T15:11:23Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2021-08-05T21:38:08Z
The following fails to compile: typedef struct Bar { int x; } Bar; int foo(Bar* b){ return ((Bar*)(b))->x; } int main(){ Bar b = {3}; return foo(&b); } The first relevant error is: bar.c(4): Error: expression expected, not `)` The `b` in the expression `((Bar*)(b))->x` has a redundant set of parentheses around it. Removing them it compiles fine. This pattern comes up a lot in the Python headers.
Comment #1 by dave287091 — 2021-08-10T07:06:46Z
Not sure if related, but this also fails to compile: int main(){ int x = 0; return (int)(x); }
Comment #2 by dlang-bot — 2021-08-10T09:51:56Z
@ibuclaw created dlang/dmd pull request #12969 "fix Issue 22182 - importC: Error: expression expected, not `)` when casting pointer with redundant parens" fixing this issue: - fix Issue 22182 - importC: Error: expression expected, not `)` when casting pointer with redundant parens https://github.com/dlang/dmd/pull/12969
Comment #3 by dlang-bot — 2021-08-10T15:11:23Z
dlang/dmd pull request #12969 "fix Issue 22182 - importC: Error: expression expected, not `)` when casting pointer with redundant parens" was merged into master: - bec9297fe026ddc94f53a23d1fb217203d36405c by Iain Buclaw: fix Issue 22182 - importC: Error: expression expected, not `)` when casting pointer with redundant parens https://github.com/dlang/dmd/pull/12969