fix Issue 21197 - Wrong lifetime inference with DIP1000 in dmd 2.093.0 (#14360)

This commit is contained in:
Walter Bright 2022-08-12 04:05:41 -07:00 committed by GitHub
parent 22d5166dca
commit 84fb2c410d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -900,7 +900,7 @@ bool checkAssignEscape(Scope* sc, Expression e, bool gag, bool byRef)
}
if (ee.op == EXP.call && ee.type.toBasetype().isTypeStruct() &&
(!va || !(va.storage_class & STC.temp)))
(!va || !(va.storage_class & STC.temp) && !va.isScope()))
{
if (sc.setUnsafeDIP1000(gag, ee.loc, "address of struct temporary returned by `%s` assigned to longer lived variable `%s`", ee, e1))
{

View file

@ -0,0 +1,25 @@
/* REQUIRED_ARGS: -preview=dip1000
*/
// https://issues.dlang.org/show_bug.cgi?id=21197
@safe void check2()
{
int random;
S create1() return scope {
return S();
}
scope S gen1 = create1;
S create2() {
return S(&random);
}
scope S gen2 = create2;
}
struct S
{
int* r;
}