diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig index 723eac4af2..2a49fa564f 100644 --- a/lib/compiler_rt/emutls.zig +++ b/lib/compiler_rt/emutls.zig @@ -296,7 +296,7 @@ const emutls_control = extern struct { .size = @sizeOf(T), .alignment = @alignOf(T), .object = .{ .index = 0 }, - .default_value = @ptrCast(?*anyopaque, default_value), + .default_value = @ptrCast(?*const anyopaque, default_value), }; } diff --git a/lib/std/enums.zig b/lib/std/enums.zig index 08781767de..ca7278b1d9 100644 --- a/lib/std/enums.zig +++ b/lib/std/enums.zig @@ -16,7 +16,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def fields = fields ++ &[_]StructField{.{ .name = field.name, .field_type = Data, - .default_value = if (field_default) |d| &d else null, + .default_value = if (field_default) |d| @ptrCast(?*const anyopaque, &d) else null, .is_comptime = false, .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0, }}; @@ -160,6 +160,20 @@ test "std.enums.directEnumArrayDefault" { try testing.expectEqual(false, array[2]); } +test "std.enums.directEnumArrayDefault slice" { + const E = enum(i4) { a = 4, b = 6, c = 2 }; + var runtime_b = "b"; + const array = directEnumArrayDefault(E, []const u8, "default", 4, .{ + .a = "a", + .b = runtime_b, + }); + + try testing.expectEqual([7][]const u8, @TypeOf(array)); + try testing.expectEqualSlices(u8, "a", array[4]); + try testing.expectEqualSlices(u8, "b", array[6]); + try testing.expectEqualSlices(u8, "default", array[2]); +} + /// Cast an enum literal, value, or string to the enum value of type E /// with the same name. pub fn nameCast(comptime E: type, comptime value: anytype) E {