Skip to content

@fieldParentPtr always fails for zero sized type field pointers. #4599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexnask opened this issue Mar 2, 2020 · 1 comment
Closed

@fieldParentPtr always fails for zero sized type field pointers. #4599

alexnask opened this issue Mar 2, 2020 · 1 comment
Milestone

Comments

@alexnask
Copy link
Contributor

alexnask commented Mar 2, 2020

const std = @import("std");

const Parent = struct {
    child: Child,
};

const Child = struct {};

test "" {
    var p = Parent{ .child = .{} };
    var c = &p.child;
    // Fails with "error: pointer value not based on parent struct", 'c' is resolved to be comptime and not set to point to a parent struct correctly.
    std.debug.assert(@fieldParentPtr(Parent, "child", c) == &p);
}

Workaround: add any non-zero sized state to Child

@alexnask alexnask changed the title @fieldParentPtr always fails for zero size type pointers. @fieldParentPtr always fails for zero sized type field pointers. Mar 2, 2020
@daurnimator daurnimator added the stage1 The process of building from source via WebAssembly and the C backend. label Mar 2, 2020
@andrewrk andrewrk removed the stage1 The process of building from source via WebAssembly and the C backend. label Mar 2, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Mar 2, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@SpexGuy
Copy link
Contributor

SpexGuy commented Nov 21, 2020

With the decision in #6706, pointers to zero-sized types are now real pointers, so this should be fixed once the compiler is updated to honor this.

@SpexGuy SpexGuy closed this as completed Nov 21, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.8.0 Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants