Jump to page: 1 24  
Page
Thread overview
[Issue 20149] [DIP1000] Local data escapes `inout` method if not decorated with `return`
[Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return`
Aug 22, 2019
Mike Franklin
Aug 22, 2019
Mike Franklin
Aug 22, 2019
Mike Franklin
Aug 22, 2019
Mike Franklin
Aug 22, 2019
Mike Franklin
Aug 22, 2019
Mike Franklin
Aug 23, 2019
Mike Franklin
Sep 04, 2019
Mike Franklin
Sep 04, 2019
Mike Franklin
Sep 04, 2019
Mike Franklin
Sep 05, 2019
Dlang Bot
Sep 05, 2019
Dlang Bot
Sep 05, 2019
Dlang Bot
Sep 07, 2019
Walter Bright
Sep 08, 2019
Walter Bright
[Issue 20149] [DIP1000] temp returned from constructor call not checked for scope problems
Sep 08, 2019
Walter Bright
Sep 09, 2019
Dlang Bot
Sep 09, 2019
Mike Franklin
Sep 09, 2019
Dlang Bot
Sep 09, 2019
Mike Franklin
Sep 09, 2019
Walter Bright
Sep 09, 2019
Mike Franklin
Sep 09, 2019
Mike Franklin
Sep 20, 2019
Dlang Bot
Sep 21, 2019
Mike Franklin
Sep 27, 2019
Dlang Bot
Oct 03, 2019
Dlang Bot
Oct 03, 2019
Dlang Bot
Oct 03, 2019
Dlang Bot
Mar 15, 2020
Walter Bright
Mar 15, 2020
Rainer Schuetze
Jun 15, 2021
Dennis
Jun 15, 2021
Dlang Bot
Feb 14, 2022
Walter Bright
[Issue 20149] [DIP1000] Local data escapes inout method if not decorated with return
Feb 15, 2022
Walter Bright
Feb 15, 2022
Dlang Bot
Feb 25, 2022
Dlang Bot
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

--- Comment #1 from Mike Franklin <slavo5150@yahoo.com> ---
> Observation-2:  Decorating `opSlice` with `return` causes a compiler error to be correctly emitted where the slice is escaping `foo`

In the example above, that should be `fun`, not `foo`.

--
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

--- Comment #2 from Mike Franklin <slavo5150@yahoo.com> ---
Interestingly removing the `inout` attribution on `opSlice` causes the compiler to emit an error at the return statement in `fun`.  I think the error should instead be emitted at the return statement of `opSlice`, but at least it doesn't compile.

--
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

--- Comment #3 from Mike Franklin <slavo5150@yahoo.com> ---
Removing all templating from the example above cause the compiler to emit what I think is correct behavior:

---
import std.stdio;

@safe:

struct ScopeBuffer
{
    this(char[4] buf, size_t len = 0)
    {
        this.buf = buf;
                this.len = len;
    }

    char[] opSlice(size_t lower, size_t upper)
    in
    {
        assert(lower <= len, "Lower bound must be less than or equal to the
length");
        assert(upper <= len, "Upper bound must be less than or equal to the
length");
        assert(lower <= upper, "Lower bound must be less than or equal to the
upper bound");
    }
    do
    {
        return buf[lower .. upper]; // GOOD: Compiler error here
    }

    char[4] buf;
    size_t len;
}

char[] fun()
{
    char[4] buf = "abcd";
    auto sb = ScopeBuffer(buf, 4);
    return sb[0..2];
}

void main()
{
    auto s = fun();
    writeln(s);
}
---
https://run.dlang.io/is/Fo1CfP

--
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

--- Comment #4 from Mike Franklin <slavo5150@yahoo.com> ---
> Removing all templating from the example above cause the compiler to emit what I think is correct behavior:

That may mean this is a duplicate of Issue 19965, but I'm not sure.

--
August 22, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=19965

--
August 23, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--
September 04, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

--- Comment #5 from Mike Franklin <slavo5150@yahoo.com> ---
A more reduced test case:

---
import std.stdio;

@safe:

struct ScopeBuffer
{
    this(char[4] init)
    {
        this.buf = init;
    }

    // The bug is that `inout` implies `return` on `this`.
    // See
https://github.com/dlang/dmd/blob/2dc5b15d1949148d460e8c809dd878e6dec8dfa3/src/dmd/func.d#L511-L513
    inout(char)[] opSlice(size_t lower, size_t upper) inout
    do
    {
        return buf[lower .. upper]; //BUG: compiler error should be emitted
here
    }

    char[4] buf;
}

char[] fun()
{
    char[4] buf = "abcd";
    auto sb = ScopeBuffer(buf);
    return sb[0..2];
}

void main()
{
    auto s = fun();
    writeln(s);
}
---
https://run.dlang.io/is/Pu1125

The problem is that the compiler is inferring `return` on `this` when decorated with `inout`.

This was discussed in issue 17927.

--
September 04, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=17927

--
September 04, 2019
https://issues.dlang.org/show_bug.cgi?id=20149

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|https://issues.dlang.org/sh |
                   |ow_bug.cgi?id=19965         |

--
« First   ‹ Prev
1 2 3 4