Thread overview
[Issue 21197] Wrong lifetime inference with DIP1000 in dmd 2.093.0
Aug 25, 2020
Atila Neves
Aug 26, 2020
Atila Neves
Jul 28, 2022
Walter Bright
Aug 11, 2022
Walter Bright
Aug 11, 2022
Dlang Bot
Aug 31, 2022
RazvanN
August 25, 2020
https://issues.dlang.org/show_bug.cgi?id=21197

Atila Neves <atila.neves@gmail.com> changed:

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

--
August 25, 2020
https://issues.dlang.org/show_bug.cgi?id=21197

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg

--- Comment #1 from moonlightsentinel@disroot.org ---
Reduced example:

==========================================
@safe void check()
{
    int random;

    auto createGenerator() {
        return RndValueGen(&random);
    }

    scope gen = createGenerator;
}

struct RndValueGen
{
    int* rnd;
}
==========================================

--
August 25, 2020
https://issues.dlang.org/show_bug.cgi?id=21197

--- Comment #2 from moonlightsentinel@disroot.org ---
digger: 788398ac6293f57ae78fca23de96b1653f729265 is the first bad commit
commit 788398ac6293f57ae78fca23de96b1653f729265
Author: Atila Neves <atila.neves@gmail.com>
Date:   Wed Jun 10 10:44:17 2020 +0100

    dmd: Merge pull request #10945 from WalterBright/fix20183

    https://github.com/dlang/dmd/pull/10945

    fix Issue 20183 - Assigning statement scope of struct literal or temp…

--
August 26, 2020
https://issues.dlang.org/show_bug.cgi?id=21197

Atila Neves <atila.neves@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression

--
July 28, 2022
https://issues.dlang.org/show_bug.cgi?id=21197

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
If we replace the struct with an equivalent pointer:

@safe void check()
{
    int random;

    auto createGenerator() {
        int* p = &random;
        return p;
    }

    scope gen = createGenerator;
}

it does compile successfully. Both should compile successfully, as the struct is just a wrapper around a pointer.

--
August 11, 2022
https://issues.dlang.org/show_bug.cgi?id=21197

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
A better test case, with and without the error message:

  @safe void check2() {
    int random;

    S create1() { return S(); }

    scope S gen1 = create1;  // no error

    S create2() { return S(&random); }

    // address of struct temporary returned by `create()` assigned to longer
lived variable `gen`
    scope S gen2 = create2;
  }

  struct S { int* r; }

--
August 11, 2022
https://issues.dlang.org/show_bug.cgi?id=21197

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright updated dlang/dmd pull request #14360 "fix Issue 21197 - Wrong lifetime inference with DIP1000 in dmd 2.093.0" fixing this issue:

- fix Issue 21197 - Wrong lifetime inference with DIP1000 in dmd 2.093.0

https://github.com/dlang/dmd/pull/14360

--
August 31, 2022
https://issues.dlang.org/show_bug.cgi?id=21197

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #6 from RazvanN <razvan.nitu1305@gmail.com> ---
This has been fixed.

--