Bug 22876 – importC: expression parsing affected by parentheses that should do nothing
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-11T19:04:30Z
Last change time
2022-03-20T08:50:37Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2022-03-11T19:04:30Z
two examples, i think they're the same bug
// test1.c
int printf(char *, ...);
int main()
{
int a = 0;
// dmd gives 1, other compilers -1
// bug disappears if the parentheses around (a) are removed
int b = - (a) - 1;
printf("%d\n", b);
}
// test2.c
int example2()
{
int *a, *b;
// Error: incompatible types for `(a) - (cast(char*)b)`: `int*` and `char*`
// works if the parentheses around (a) are removed
long diff = (char*)(a) - (char*)b;
}
Comment #1 by duser — 2022-03-11T20:53:11Z
one more example that i forgot to add:
void fn()
{
int *p;
// Error: `p` is not of integral type, it is a `int*`
// Error: `cast(int*)1` is not of integral type, it is a `int*`
// works if parentheses around (p) are removed
unsigned x = (unsigned)(p) & 1;
}
there's no ambiguous cast in this one so i've changed the issue title to something that should apply to all the examples
Comment #2 by dlang-bot — 2022-03-18T08:52:47Z
@WalterBright created dlang/dmd pull request #13831 "fix Issue 22876 - importC: expression parsing affected by parentheses…" fixing this issue:
- fix Issue 22876 - importC: expression parsing affected by parentheses that should do nothing
https://github.com/dlang/dmd/pull/13831
Comment #3 by dlang-bot — 2022-03-20T08:50:37Z
dlang/dmd pull request #13831 "fix Issue 22876 - importC: expression parsing affected by parentheses…" was merged into master:
- b25875b21fdd855b403a2254feb29b1b3385a795 by Walter Bright:
fix Issue 22876 - importC: expression parsing affected by parentheses that should do nothing
https://github.com/dlang/dmd/pull/13831