[Issue 24145] New: subtracting pointers with different types is both deprecated and an error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 13 21:54:40 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24145

          Issue ID: 24145
           Summary: subtracting pointers with different types is both
                    deprecated and an error
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: elpenguino+D at gmail.com

```
void main() {
    auto foo = (ushort*).init - (ubyte*).init;
}
```
As of DMD 2.105.0, this code prints a deprecation and an error:
```
test.d(2): Deprecation: cannot subtract pointers to different types: `ushort*`
and `ubyte*`.
test.d(2): Error: incompatible types for ((null) - (null)): 'ushort*' and
'ubyte*'
```

This appears to be the case as far back as 2.078.x. There is a changelog entry
for its deprecation in 2.078.0's release, but why was it deprecated when it
already didn't compile?

--


More information about the Digitalmars-d-bugs mailing list