Merge pull request #20577 from thewilsonator/pointer-subtract

Make subtracting pointers of different types an error
This commit is contained in:
Dennis 2025-01-09 15:06:33 +01:00 committed by GitHub
commit 69664b922d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 10 deletions

View file

@ -0,0 +1,11 @@
An error is now given for subtracting pointers of different types
The following code now gives errors:
```
static assert(cast(void*)8 - cast(int*) 0 == 2L);
static assert(cast(int*) 8 - cast(void*)0 == 8L);
void test()
{
auto foo = (ushort*).init - (ubyte*).init;
}
```