-
-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REG2.067a] Issue 13775 - Broken explicit casting of dynamic array slices of known size to static array of different type #4193
Conversation
…known size to static array of different type Support reinterpret-cast from a CT-known boundaries slice expression that can be implicitly typed as `T[n]` to another static array type `U[m]`, iff their sizes are same (`T[n].sizeof == U[m].sizeof`).
|
I don't see any problems with this. |
|
Auto-merge toggled on |
[REG2.067a] Issue 13775 - Broken explicit casting of dynamic array slices of known size to static array of different type
|
This code broke the following (used in ae, breaking Digger): immutable(ubyte)[] data = new ubyte[20].idup;
auto a = cast(ubyte[20])data[0..$];Was this breakage intentional? |
|
Thanks for tracing this @CyberShadow :) Also affects Vibe.d: |
This PR intentionally rejects the case, because there was a wrong-code bug. See the example code: void main() {
immutable(ubyte)[] data = new ubyte[2].idup;
auto a = cast(ubyte[4])data[0..$];
// Although $ == 2, the cast will access out of the range of valid memory.
import std.stdio;
writeln(a);
// will print [0, 0, garbage, garbage]
}And, until 2.062, the reinterpret cast from T[] to T[n] had been constantly disallowed. So the restriction is merely enabled again. |
|
IMHO this should be a runtime check, like with slice copies. So it should throw |
|
Of course it's possible, but at least it should be a new enhancement. And the cast would not work under the |
I thought asserts were exempt from |
|
I don't know. At least today range violation handling is not same with assert(false) even in @nogc function. |
|
Another regression filed against this change: |
https://issues.dlang.org/show_bug.cgi?id=13775
Support reinterpret-cast from a CT-known boundaries slice expression that can be implicitly typed as
T[n]to another static array typeU[m], iff their sizes are same (T[n].sizeof == U[m].sizeof).