Bug 11006 – Subtraction of pointers for `void` and non-void types compiles

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-10T01:00:57Z
Last change time
2017-12-18T22:57:16Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Denis Shelomovskii

Comments

Comment #0 by verylonglogin.reg — 2013-09-10T01:00:57Z
According to docs: "For -, the pointers are subtracted and the result is divided by the size of the type pointed to by the operands. It is an error if the pointers point to different types." Both passes (giving unexpected results) but should reject to compile: --- static assert(cast(void*) 8 - cast(int*) 0 == 2); static assert(cast(int*) 8 - cast(void*) 0 == 8); --- Looks like a high danger for generic code.
Comment #1 by andrej.mitrovich — 2013-09-10T13:38:29Z
Fixed typo.
Comment #2 by bitter.taste — 2017-01-13T22:35:00Z
Comment #3 by bugzilla — 2017-11-20T03:56:29Z
Comment #4 by github-bugzilla — 2017-11-20T04:59:32Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1cf383600f21394b12e2077ae97c4944f53c5e2b Fix Issue 11006 - Subtraction of pointers for void and non-void types compiles https://github.com/dlang/dmd/commit/523301bf58ac8c2ea68269dc7628812d5697c863 Merge pull request #7332 from JinShil/fix_11006 Fix Issue 11006 - Subtraction of pointers for void and non-void type compiles merged-on-behalf-of: Walter Bright <[email protected]>
Comment #5 by github-bugzilla — 2017-12-18T22:57:16Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1cf383600f21394b12e2077ae97c4944f53c5e2b Fix Issue 11006 - Subtraction of pointers for void and non-void types compiles https://github.com/dlang/dmd/commit/523301bf58ac8c2ea68269dc7628812d5697c863 Merge pull request #7332 from JinShil/fix_11006