| author | |
| committer | |
| log | 26183660558c43133d862912c602e316f43698c7 |
| tree | 7f3b8aea43d6f68f42592d7a9b7c612a316e7a03 |
| parent | 3237528a592f2dc22659f77f5fbfb061dc14566a |
Fixes #41762 files changed, 16 insertions(+), 1 deletions(-)
src/ir.cpp+2-1| ... | ... | @@ -11592,7 +11592,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 11592 | 11592 | wanted_ptr_type->data.pointer.sentinel == nullptr || |
| 11593 | 11593 | (actual_ptr_type->data.pointer.sentinel != nullptr && |
| 11594 | 11594 | const_values_equal(ira->codegen, wanted_ptr_type->data.pointer.sentinel, |
| 11595 | actual_ptr_type->data.pointer.sentinel)); | |
| 11595 | actual_ptr_type->data.pointer.sentinel)) || | |
| 11596 | actual_ptr_type->data.pointer.ptr_len == PtrLenC; | |
| 11596 | 11597 | if (!ok_null_term_ptrs) { |
| 11597 | 11598 | result.id = ConstCastResultIdPtrSentinel; |
| 11598 | 11599 | result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1); |
test/stage1/behavior/cast.zig+14| ... | ... | @@ -768,3 +768,17 @@ test "variable initialization uses result locations properly with regards to the |
| 768 | 768 | const x: i32 = if (b) 1 else 2; |
| 769 | 769 | expect(x == 1); |
| 770 | 770 | } |
| 771 | ||
| 772 | test "cast between [*c]T and ?[*:0]T on fn parameter" { | |
| 773 | const S = struct { | |
| 774 | const Handler = ?extern fn ([*c]const u8) void; | |
| 775 | fn addCallback(handler: Handler) void {} | |
| 776 | ||
| 777 | fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {} | |
| 778 | ||
| 779 | fn doTheTest() void { | |
| 780 | addCallback(myCallback); | |
| 781 | } | |
| 782 | }; | |
| 783 | S.doTheTest(); | |
| 784 | } |