May 14, 2021

On Wednesday, 12 May 2021 at 13:14:30 UTC, Dennis wrote:

>

The root cause is:
Issue 20150 - -dip1000 defeated by pure

Moreover, the code example

int* escape(int* r) @safe pure
{
    return r;
}

int* f() @safe
{
    int x = 42;
    return escape(&x); /* Should not compile. */
}

referenced at [1] correctly fails to compile with dmd master using -dip1000 as

main.d(9,20): Error: cannot take address of local `x` in `@safe` function `f`

Again, I fail to see the problem here.

[1] https://issues.dlang.org/show_bug.cgi?id=20150

May 14, 2021

On Friday, 14 May 2021 at 09:15:18 UTC, Per Nordlöw wrote:

>

fails to compile with dmd master using -dip1000 as

main.d(9,20): Error: cannot take address of local `x` in `@safe` function `f`

That's the old error message, I don't understand how you get that with -dip1000, I can only reproduce that by forgetting that flag.

May 14, 2021

On Friday, 14 May 2021 at 09:02:35 UTC, Per Nordlöw wrote:

>

I fail to see the general issue here.

Nevermind this comment. I see the problem now, thanks. I was given the code example

int bad_global = 1;

@safe pure void purefunc(int* x)
{
    *x = 2;
}

void main()
{
    assert(bad_global == 1);
    purefunc(&bad_global);
    assert(bad_global == 2);
}

that incorrectly succeeds to compile [1].

[1] https://run.dlang.io/?compiler=dmd&source=int%20bad_global%20%3D%201;%0Apure%20void%20purefunc(int*%20x)%0A%7B%0A%20%20%20%20*x%20%3D%202;%0A%7D%0Avoid%20main()%0A%7B%0A%20%20%20%20assert(bad_global%20%3D%3D%201);%0A%20%20%20%20purefunc(%26bad_global);%0A%20%20%20%20assert(bad_global%20%3D%3D%202);%0A%7D

May 14, 2021

On Friday, 14 May 2021 at 09:41:01 UTC, Dennis wrote:

>

On Friday, 14 May 2021 at 09:15:18 UTC, Per Nordlöw wrote:

>

fails to compile with dmd master using -dip1000 as

main.d(9,20): Error: cannot take address of local `x` in `@safe` function `f`

That's the old error message, I don't understand how you get that with -dip1000, I can only reproduce that by forgetting that flag.

Are you using dmd master?

May 14, 2021

On Friday, 14 May 2021 at 09:43:53 UTC, Per Nordlöw wrote:

> >

That's the old error message, I don't understand how you get that with -dip1000, I can only reproduce that by forgetting that flag.

Ahh, sorry my script used -dip1008 not -dip1000. Didn't see the difference.

May 14, 2021

On Wednesday, 12 May 2021 at 13:14:30 UTC, Dennis wrote:

>

Why is this not fixed?

Walter made a PR for fixing the behavior in dmd: (March 2020)
https://github.com/dlang/dmd/pull/10924

Later, aG0aep6G made a better fix: (November 2020)
https://github.com/dlang/dmd/pull/12010

I vote for modifying this PR to emit a deprecation message for the new case not covered by phobos and many other projects.

May 14, 2021

On Friday, 14 May 2021 at 09:02:35 UTC, Per Nordlöw wrote:

>

No, pure function can neither access module global nor process global (__gshared) variables whatsoever regardless of scope nor return qualifier on parameters and return type.

Please show an example that contradicts this statement.

I can't, I agree with the statement.

I'm not saying that adding scope or return breaks pure, it's the other way around.
Adding pure breaks scope, since the compiler incorrectly assumes that a pure function implies that the parameters are scope.

1 2
Next ›   Last »