Skip to content

Commit 3206fb2

Browse files
authored
Merge pull request #11881 from WalterBright/fix21324
fix Issue 21324 - @LiVe not detecting overwrite of Owner without disp…
2 parents 0e3e0f9 + b5b08e7 commit 3206fb2

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/dmd/ob.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,12 @@ void checkObErrors(ref ObState obstate)
19771977
else if (isReadonlyPtr(v))
19781978
pvs.state = PtrState.Readonly;
19791979
else
1980+
{
1981+
if (pvs.state == PtrState.Owner && v.type.hasPointersToMutableFields())
1982+
v.error(e.loc, "assigning to Owner without disposing of owned value");
1983+
19801984
pvs.state = PtrState.Owner;
1985+
}
19811986
pvs.deps.zero();
19821987

19831988
EscapeByResults er;

test/fail_compilation/fob1.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fail_compilation/fob1.d(104): Error: variable `fob1.foo1.p` is returned but is U
1717

1818
/* TEST_OUTPUT:
1919
---
20+
fail_compilation/fob1.d(204): Error: variable `fob1.foo2.p` assigning to Owner without disposing of owned value
2021
fail_compilation/fob1.d(203): Error: variable `fob1.foo2.p` is left dangling at return
2122
---
2223
*/

test/fail_compilation/fob2.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,21 @@ void free7(int*);
175175
{
176176
free7(p);
177177
}
178+
179+
/* TEST_OUTPUT:
180+
---
181+
fail_compilation/fob2.d(807): Error: variable `fob2.test8.p` assigning to Owner without disposing of owned value
182+
---
183+
*/
184+
185+
#line 800
186+
187+
int* malloc8();
188+
void free8(int*);
189+
190+
@live void test8()
191+
{
192+
int* p = malloc8();
193+
p = malloc8(); // error here
194+
free8(p);
195+
}

0 commit comments

Comments
 (0)