No modification of pointer values in safe functions?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jan 3 22:42:07 UTC 2018


On Wednesday, January 03, 2018 22:25:16 Mark via Digitalmars-d-learn wrote:
> On Wednesday, 3 January 2018 at 22:12:01 UTC, Jonathan M Davis
>
> wrote:
> > On Wednesday, January 03, 2018 22:02:22 Mark via
> >
> > Digitalmars-d-learn wrote:
> >> The documentation says the modification of pointer values is
> >> not allowed in safe functions. Yet the following compiles fine
> >> on dmd:
> >>
> >> void main() @safe
> >> {
> >>
> >>   int* x = new int;
> >>   int* y = new int;
> >>   y=x;
> >>
> >> }
> >>
> >> Is this simply a compiler bug?
> >
> > Where are you reading that in the documentation? There's
> > nothing unsafe whatsoever about assigning one pointer to
> > another.
> >
> > Now, pointer arithmetic is unsafe, and that's forbidden in
> > @safe functions. So, I suspect that you're ether
> > misunderstanding the documentation and/or the documentation
> > isn't clear enough.
> >
> > - Jonathan M Davis
>
> https://dlang.org/spec/function.html#safe-functions
>
> "The following operations are not allowed in safe functions:
>
> [...]
> - No modification of pointer values.
> [...]"

Then the spec needs to be clarified. Assignment is fine but other types of
mutation are not.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list