D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22876 - importC: expression parsing affected by parentheses that should do nothing
Summary: importC: expression parsing affected by parentheses that should do nothing
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull
Depends on:
Blocks:
 
Reported: 2022-03-11 19:04 UTC by duser
Modified: 2022-03-20 08:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description duser 2022-03-11 19:04:30 UTC
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 duser 2022-03-11 20:53:11 UTC
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 Dlang Bot 2022-03-18 08:52:47 UTC
@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 Dlang Bot 2022-03-20 08:50:37 UTC
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