Add implicit cast for *[N]T to [*c]T
This commit is contained in:
parent
21c60922e3
commit
b118806c69
|
@ -12773,9 +12773,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
|
|||
}
|
||||
}
|
||||
|
||||
// *[N]T to [*]T
|
||||
// *[N]T to [*]T and [*c]T
|
||||
if (wanted_type->id == ZigTypeIdPointer &&
|
||||
wanted_type->data.pointer.ptr_len == PtrLenUnknown &&
|
||||
(wanted_type->data.pointer.ptr_len == PtrLenUnknown || wanted_type->data.pointer.ptr_len == PtrLenC) &&
|
||||
actual_type->id == ZigTypeIdPointer &&
|
||||
actual_type->data.pointer.ptr_len == PtrLenSingle &&
|
||||
actual_type->data.pointer.child_type->id == ZigTypeIdArray)
|
||||
|
|
|
@ -404,6 +404,16 @@ test "implicit cast from *[N]T to ?[*]T" {
|
|||
expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
|
||||
}
|
||||
|
||||
test "implicit cast from *[N]T to [*c]T" {
|
||||
var x: [4]u16 = [4]u16{ 0, 1, 2, 3 };
|
||||
var y: [*c]u16 = &x;
|
||||
|
||||
expect(std.mem.eql(u16, x[0..4], y[0..4]));
|
||||
x[0] = 8;
|
||||
y[3] = 6;
|
||||
expect(std.mem.eql(u16, x[0..4], y[0..4]));
|
||||
}
|
||||
|
||||
test "implicit cast from *T to ?*c_void" {
|
||||
var a: u8 = 1;
|
||||
incrementVoidPtrValue(&a);
|
||||
|
|
Loading…
Reference in New Issue
Block a user