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