[Issue 24754] cannot take address of a member array in a ref foreach
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 12 22:22:15 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24754
--- Comment #4 from Luís Ferreira <contact at lsferreira.net> ---
> Pointers are not allowed in @safe functions at all.
What are you talking about? They are, its specified in the spec. 20.24.1. Safe
Functions.
Please don't close tickets as invalid as you see them and just because you
think they are invalid. It's not productive for anyone. Maybe someone else
sympathize with the same problem, you might not have enough understanding of
it, ask for elaboration, or present arguments against it...
---
> That's not a bug, it's a feature!
This is a bug, and an industry facing bug. Probably one of the reasons no one
at industry use or rely on it (e.g. like people do in Rust), in practice,
@safe, is because its buggy and have holes. Being restrictive at the point of
not allowing pointers is not a real feature, if D didn't allow pointers. It
would certainly make the feature even less adopted.
It's another question if we would discuss if D allows a subset of pointers only
(like ref variables, or like Zig does, define the pointer semantic restrictions
in the type), but that goes out of scope both from what is defined in spec and
what we have today.
Also if pointers was the real problem, explain why this code compiles:
```
struct Foo
{
int[] foo;
@safe
void foobar()
{
int* f;
foreach(i; 0 .. foo.length)
f = &foo[i];
}
}
void main()
{
Foo foo;
foo.foobar();
}
```
It uses pointers, doesn't it?
--
More information about the Digitalmars-d-bugs
mailing list