File tree 2 files changed +19
-2
lines changed 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1841,8 +1841,11 @@ fn transInitListExprRecord(
1841
1841
// .field_name = expr
1842
1842
const period_tok = try appendToken (rp .c , .Period , "." );
1843
1843
1844
- const raw_name = try rp .c .str (ZigClangDecl_getName_bytes_begin (@ptrCast (* const ZigClangDecl , field_decl )));
1845
- if (raw_name .len < 1 ) continue ;
1844
+ var raw_name = try rp .c .str (ZigClangDecl_getName_bytes_begin (@ptrCast (* const ZigClangDecl , field_decl )));
1845
+ if (ZigClangFieldDecl_isAnonymousStructOrUnion (field_decl )) {
1846
+ const name = rp .c .decl_table .get (@ptrToInt (ZigClangFieldDecl_getCanonicalDecl (field_decl ))).? ;
1847
+ raw_name = try mem .dupe (rp .c .a (), u8 , name .value );
1848
+ }
1846
1849
const field_name_tok = try appendIdentifier (rp .c , raw_name );
1847
1850
1848
1851
_ = try appendToken (rp .c , .Equal , "=" );
Original file line number Diff line number Diff line change @@ -39,4 +39,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
39
39
\\ return 0;
40
40
\\}
41
41
, "" );
42
+
43
+ cases .add ("anonymous struct & unions" ,
44
+ \\#include <stdlib.h>
45
+ \\#include <stdint.h>
46
+ \\static struct { struct { uint16_t x, y; }; } x = { 1 };
47
+ \\static struct { union { uint32_t x; uint8_t y; }; } y = { 0x55AA55AA };
48
+ \\int main(int argc, char **argv) {
49
+ \\ if (x.x != 1) abort();
50
+ \\ if (x.y != 0) abort();
51
+ \\ if (y.x != 0x55AA55AA) abort();
52
+ \\ if (y.y != 0xAA) abort();
53
+ \\ return 0;
54
+ \\}
55
+ , "" );
42
56
}
You can’t perform that action at this time.
0 commit comments