Add run-translated-c test & fix one more edge case
parent
2da9e0060b
commit
62413da9d3
|
@ -1841,8 +1841,11 @@ fn transInitListExprRecord(
|
|||
// .field_name = expr
|
||||
const period_tok = try appendToken(rp.c, .Period, ".");
|
||||
|
||||
const raw_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, field_decl)));
|
||||
if (raw_name.len < 1) continue;
|
||||
var raw_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, field_decl)));
|
||||
if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) {
|
||||
const name = rp.c.decl_table.get(@ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl))).?;
|
||||
raw_name = try mem.dupe(rp.c.a(), u8, name.value);
|
||||
}
|
||||
const field_name_tok = try appendIdentifier(rp.c, raw_name);
|
||||
|
||||
_ = try appendToken(rp.c, .Equal, "=");
|
||||
|
|
|
@ -39,4 +39,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
|
|||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("anonymous struct & unions",
|
||||
\\#include <stdlib.h>
|
||||
\\#include <stdint.h>
|
||||
\\static struct { struct { uint16_t x, y; }; } x = { 1 };
|
||||
\\static struct { union { uint32_t x; uint8_t y; }; } y = { 0x55AA55AA };
|
||||
\\int main(int argc, char **argv) {
|
||||
\\ if (x.x != 1) abort();
|
||||
\\ if (x.y != 0) abort();
|
||||
\\ if (y.x != 0x55AA55AA) abort();
|
||||
\\ if (y.y != 0xAA) abort();
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue