[Issue 23565] New: Change `$` semantics so that it works with `.ptr` too
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Dec 17 02:53:57 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23565
          Issue ID: 23565
           Summary: Change `$` semantics so that it works with `.ptr` too
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com
We can use `.ptr` in slice and indexes expressions to bypass bounds
verification but then we lose the opportunity to use `$` for the subscripts,
even if an array and hence a `.length` is possible.
I propose to enhance the semantics of `$` so that this code compiles and
execute
```d
void main()
{
    auto b = new int[](2);
    b.ptr[0 .. $] = [1,2]; // b.ptr[0 .. b.length] = [1,2];
    assert(b == [1,2]);
    b.ptr[$-1] = 3;
    assert(b == [1,3]);
}   
```
This would break nothing as this is currently rejected, e.g for the example
with
> Error: undefined identifier `$`
--
    
    
More information about the Digitalmars-d-bugs
mailing list