Comment #0 by pro.mathias.lang — 2020-03-04T03:38:04Z
```
void main () @safe
{
auto ptr = [ 42 ].ptr;
}
```
This errors out, even tho it is perfectly @safe.
```
foo.d(3): Error: [42].ptr cannot be used in @safe code, use &[42][0] instead
```
DMD v2.090.1
Comment #1 by nick — 2023-07-05T15:56:20Z
The reason for this error is to prevent `[42][1..1].ptr`, which is not @safe. Your example could be allowed if the literal has not been sliced.
Comment #2 by dlang-bot — 2023-09-06T16:05:06Z
@ntrel created dlang/dmd pull request #15581 "Allow using .ptr in @safe code when pointer is safe to dereference" fixing this issue:
- Fix Issue 20634 - @safe forces bounds checking on newly allocated array when using .ptr
Also allow for any string literal.
https://github.com/dlang/dmd/pull/15581
Comment #3 by dlang-bot — 2023-09-13T10:03:14Z
@ntrel updated dlang/dmd pull request #15572 "Fix Issue 24135 - Eponymous template member overloads not shown as call candidates" fixing this issue:
- Fix Issue 20634 - @safe forces bounds checking on newly allocated array when using .ptr
Also allow for any string literal.
https://github.com/dlang/dmd/pull/15572
Comment #4 by nick — 2023-09-13T12:04:28Z
Note: The second commit was wrongly included in that pull and has been removed.
Comment #5 by robert.schadek — 2024-12-13T19:07:25Z