-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow ref on locals, globals, and statics
- Loading branch information
1 parent
e60bfd1
commit 6e23bc0
Showing
3 changed files
with
49 additions
and
4 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,12 @@ | ||
`ref` can now be applied to local, static, extern, and global variables | ||
|
||
For example, one can now write: | ||
``` | ||
void main() | ||
{ | ||
int i; | ||
ref int r = i; | ||
r = 3; | ||
assert(i == 3); | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,13 +1,46 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/diag9679.d(11): Error: variable `diag9679.main.n` - only parameters, functions and `foreach` declarations can be `ref` | ||
fail_compilation/diag9679.d(12): Error: variable `diag9679.main.n` - storage class `auto` has no effect if type is not inferred, did you mean `scope`? | ||
fail_compilation/diag9679.d(15): Error: variable `diag9679.main.n` - storage class `auto` has no effect if type is not inferred, did you mean `scope`? | ||
fail_compilation/diag9679.d(16): Error: variable `diag9679.main.S.a` - field declarations cannot be `ref` | ||
fail_compilation/diag9679.d(23): Error: returning `r` escapes a reference to local variable `r` | ||
fail_compilation/diag9679.d(30): Error: returning `r` escapes a reference to local variable `r` | ||
--- | ||
*/ | ||
|
||
|
||
void main() | ||
{ | ||
if (ref n = 1) {} | ||
if (auto int n = 1) {} | ||
struct S { ref int a; } | ||
} | ||
|
||
ref int test2() | ||
{ | ||
int i; | ||
ref r = i; | ||
return r; | ||
} | ||
|
||
ref int test3() | ||
{ | ||
extern int i; | ||
ref r = i; | ||
return r; | ||
} | ||
|
||
struct S { int a; } | ||
|
||
void test4() | ||
{ | ||
S s; | ||
ref int r1 = s.a; | ||
r1 = 3; | ||
__gshared S t2; | ||
ref int r2 = t2.a; | ||
static S t3; | ||
ref int r3 = t3.a; | ||
extern S t4; | ||
ref int r4 = t4.a; | ||
} |