| author | |
| committer | |
| log | 882aa868436a8e2562ffbdb9f5f7551b6808873f |
| tree | bc9c7e9f603de31f16d04e40461cc64ba9c8eb83 |
| parent | f21ac0220aa16cc1376cc001d123c8ad25607ecd |
2 files changed, 25 insertions(+), 1 deletions(-)
src-self-hosted/translate_c.zig+1-1| ... | @@ -811,7 +811,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -811,7 +811,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 811 | 811 | ||
| 812 | var is_anon = false; | 812 | var is_anon = false; |
| 813 | var raw_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl))); | 813 | var raw_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl))); |
| 814 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl) or (std.Target.current.abi == .msvc and raw_name.len == 0)) { | 814 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl) or raw_name.len == 0) { |
| 815 | raw_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); | 815 | raw_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); |
| 816 | is_anon = true; | 816 | is_anon = true; |
| 817 | } | 817 | } |
test/translate_c.zig+24| ... | @@ -2853,4 +2853,28 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2853,4 +2853,28 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2853 | , &[_][]const u8{ | 2853 | , &[_][]const u8{ |
| 2854 | \\pub const FOO = 0x61626364; | 2854 | \\pub const FOO = 0x61626364; |
| 2855 | }); | 2855 | }); |
| 2856 | |||
| 2857 | if (std.Target.current.abi == .msvc) { | ||
| 2858 | cases.add("nameless struct fields on msvc", | ||
| 2859 | \\typedef struct NAMED | ||
| 2860 | \\{ | ||
| 2861 | \\ long name; | ||
| 2862 | \\} NAMED; | ||
| 2863 | \\ | ||
| 2864 | \\typedef struct ONENAMEWITHSTRUCT | ||
| 2865 | \\{ | ||
| 2866 | \\ NAMED; | ||
| 2867 | \\ long b; | ||
| 2868 | \\} ONENAMEWITHSTRUCT; | ||
| 2869 | , &[_][]const u8{ | ||
| 2870 | \\pub const struct_NAMED = extern struct { | ||
| 2871 | \\ name: c_long, | ||
| 2872 | \\}; | ||
| 2873 | \\pub const NAMED = struct_NAMED; | ||
| 2874 | \\pub const struct_ONENAMEWITHSTRUCT = extern struct { | ||
| 2875 | \\ unnamed_1: struct_NAMED, | ||
| 2876 | \\ b: c_long, | ||
| 2877 | \\}; | ||
| 2878 | }); | ||
| 2879 | } | ||
| 2856 | } | 2880 | } |