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 @@ -23,4 +23,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
23
23
\\ return 0;
24
24
\\}
25
25
, "" );
26
+
27
+ cases .add ("anonymous struct & unions" ,
28
+ \\#include <stdlib.h>
29
+ \\#include <stdint.h>
30
+ \\static struct { struct { uint16_t x, y; }; } x = { 1 };
31
+ \\static struct { union { uint32_t x; uint8_t y; }; } y = { 0x55AA55AA };
32
+ \\int main(int argc, char **argv) {
33
+ \\ if (x.x != 1) abort();
34
+ \\ if (x.y != 0) abort();
35
+ \\ if (y.x != 0x55AA55AA) abort();
36
+ \\ if (y.y != 0xAA) abort();
37
+ \\ return 0;
38
+ \\}
39
+ , "" );
26
40
}
You can’t perform that action at this time.
0 commit comments