Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 9537 - auto ref returns a reference its own stack
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/fail9537.d(26): Error: foo(tuple(1, 2)) is not an lvalue | ||
--- | ||
*/ | ||
|
||
struct Tuple(T...) | ||
{ | ||
T field; | ||
alias field this; | ||
} | ||
|
||
Tuple!T tuple(T...)(T args) | ||
{ | ||
return Tuple!T(args); | ||
} | ||
|
||
auto ref foo(T)(auto ref T t) | ||
{ | ||
return t[0]; // t[0] is deduced to non-ref | ||
} | ||
|
||
void main() | ||
{ | ||
int* p = &foo(tuple(1, 2)); | ||
} |