Add implicit cast for *[N]T to [*c]T

master
SamTebbs33 2019-07-05 00:00:12 +01:00 committed by Andrew Kelley
parent 21c60922e3
commit b118806c69
2 changed files with 12 additions and 2 deletions

View File

@ -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)

View File

@ -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);