Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8036 from WalterBright/fix18484
fix Issue 18484 - [dip1000] Subtype allows reference to escape with i… merged-on-behalf-of: Walter Bright <WalterBright@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* REQUIRED_ARGS: -dip1000 | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/test18484.d(19): Error: returning `x.bar()` escapes a reference to local variable `x` | ||
fail_compilation/test18484.d(24): Error: escaping reference to stack allocated value returned by `S(0)` | ||
--- | ||
*/ | ||
|
||
// https://issues.dlang.org/show_bug.cgi?id=18484 | ||
|
||
struct S | ||
{ | ||
int* bar() return; | ||
int i; | ||
} | ||
|
||
int* test1() | ||
{ | ||
auto x = S(); return x.bar(); // error | ||
} | ||
|
||
int* test2() | ||
{ | ||
return S().bar(); // error | ||
} | ||
|