-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 20183 - Assigning statement scope of struct literal or temp…
…orary to variable with longer lifetime
- Loading branch information
1 parent
74190e5
commit 37a695f
Showing
3 changed files
with
52 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,28 @@ | ||
/* REQUIRED_ARGS: -preview=dip1000 | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/fail20183.d(1016): Error: cannot modify constant expression `S(0).i` | ||
fail_compilation/fail20183.d(1017): Error: address of struct temporary returned by `s()` assigned to longer lived variable `q` | ||
--- | ||
*/ | ||
|
||
#line 1000 | ||
|
||
// https://issues.dlang.org/show_bug.cgi?id=20183 | ||
|
||
@safe: | ||
|
||
int* addr(return ref int b) { return &b; } | ||
|
||
struct S | ||
{ | ||
int i; | ||
} | ||
|
||
S s() { return S(); } | ||
|
||
void test() | ||
{ | ||
int* p = addr(S().i); // struct literal | ||
int* q = addr(s().i); // struct temporary | ||
} |
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