-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #20644 cast(ref T) as shorthand for *cast(T*)&
- Loading branch information
1 parent
d6f693b
commit 07d16f7
Showing
4 changed files
with
59 additions
and
2 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,11 @@ | ||
Add cast(ref T)e as shorthand for *cast(T*)&e | ||
|
||
A `cast(ref T)e` takes `e` representing an lvalue and forcibly changes | ||
its type to `T`. It is equivalent to the expression `*cast(T*)&e`. | ||
) | ||
|
||
--- | ||
int i = 73; | ||
float f = *cast(float*)&i; // reinterprets the integer bit pattern as a float | ||
float g = cast(ref float)i; // equivalent to the previous statement | ||
--- |
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,11 @@ | ||
/* TEST_OUTPUT: | ||
--- | ||
fail_compilation/castref.d(10): Error: `cast(ref` needs to be followed with a type | ||
--- | ||
*/ | ||
|
||
void test() | ||
{ | ||
int* p; | ||
char* q = cast(ref const)p; | ||
} |
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