mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
fix Issue 21197 - Wrong lifetime inference with DIP1000 in dmd 2.093.0 (#14360)
This commit is contained in:
parent
22d5166dca
commit
84fb2c410d
2 changed files with 26 additions and 1 deletions
|
@ -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))
|
||||
{
|
||||
|
|
25
compiler/test/compilable/test21197.d
Normal file
25
compiler/test/compilable/test21197.d
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue