Open pfgithub opened 1 year ago
I just hit this again. This should maybe fix it:
diff --git a/src/translate_c.zig b/src/translate_c.zig
index 148b73955b..3806c5d174 100644
--- a/src/translate_c.zig
+++ b/src/translate_c.zig
@@ -3323,7 +3323,11 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re
}
}
const decl = @as(*const clang.NamedDecl, @ptrCast(member_decl));
- break :blk try c.str(decl.getName_bytes_begin());
+ const res = try c.str(decl.getName_bytes_begin());
+ if(res.len == 0) {
+ break :blk "anonymous";
+ }
+ break :blk res;
};
var node = try Tag.field_access.create(c.arena, .{ .lhs = container_node, .field_name = name });
The correct fix is to check if the struct was demoted to opaque and fail the function.
diff --git a/src/translate_c.zig b/src/translate_c.zig
index 8778310751..b027399c59 100644
--- a/src/translate_c.zig
+++ b/src/translate_c.zig
@@ -3305,6 +3305,8 @@ fn transStmtExpr(c: *Context, scope: *Scope, stmt: *const clang.StmtExpr, used:
}
fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, result_used: ResultUsed) TransError!Node {
+ if (qualTypeWasDemotedToOpaque(c, stmt.getType()))
+ return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "cannot get member of struct demoted to opaque", .{});
var container_node = try transExpr(c, scope, stmt.getBase(), .used);
if (stmt.isArrow()) {
container_node = try Tag.deref.create(c.arena, container_node);
Zig Version
0.11.0-dev.3905+309aacfc8
Steps to Reproduce and Observed Behavior
Expected Behavior
It should not block compilation, for example by accessing
.unnamed_0
instead or generating a@compileError