| author | |
| committer | |
| log | b118806c69e44029a7af9c9b8bdfa9cdcd280260 |
| tree | a76bb5a3b4d9d3c407a81d6c7924b9f338cb293a |
| parent | 21c60922e3514ca15fa505efb380fb37fde8d62a |
2 files changed, 12 insertions(+), 2 deletions(-)
src/ir.cpp+2-2| ... | @@ -12773,9 +12773,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12773,9 +12773,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12773 | } | 12773 | } |
| 12774 | } | 12774 | } |
| 12775 | 12775 | ||
| 12776 | // *[N]T to [*]T | 12776 | // *[N]T to [*]T and [*c]T |
| 12777 | if (wanted_type->id == ZigTypeIdPointer && | 12777 | if (wanted_type->id == ZigTypeIdPointer && |
| 12778 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && | 12778 | (wanted_type->data.pointer.ptr_len == PtrLenUnknown || wanted_type->data.pointer.ptr_len == PtrLenC) && |
| 12779 | actual_type->id == ZigTypeIdPointer && | 12779 | actual_type->id == ZigTypeIdPointer && |
| 12780 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 12780 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 12781 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) | 12781 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
test/stage1/behavior/cast.zig+10| ... | @@ -404,6 +404,16 @@ test "implicit cast from *[N]T to ?[*]T" { | ... | @@ -404,6 +404,16 @@ test "implicit cast from *[N]T to ?[*]T" { |
| 404 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | 404 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | test "implicit cast from *[N]T to [*c]T" { | ||
| 408 | var x: [4]u16 = [4]u16{ 0, 1, 2, 3 }; | ||
| 409 | var y: [*c]u16 = &x; | ||
| 410 | |||
| 411 | expect(std.mem.eql(u16, x[0..4], y[0..4])); | ||
| 412 | x[0] = 8; | ||
| 413 | y[3] = 6; | ||
| 414 | expect(std.mem.eql(u16, x[0..4], y[0..4])); | ||
| 415 | } | ||
| 416 | |||
| 407 | test "implicit cast from *T to ?*c_void" { | 417 | test "implicit cast from *T to ?*c_void" { |
| 408 | var a: u8 = 1; | 418 | var a: u8 = 1; |
| 409 | incrementVoidPtrValue(&a); | 419 | incrementVoidPtrValue(&a); |