Skip to content

Add compiler error for using @intFromPtr on bit aligned pointer #2677

@Hejsil

Description

@Hejsil

Since bit aligned pointers is represented as meta data on the pointer type at compile time, it doesn't make sense to allow @ptrToInt on these pointers, as the address cannot be represented at runtime.

const A = packed struct {
    a: u4,
    b: u4
};

test \"\" {
    var a: A = undefined;
    _ = @ptrToInt(&a.a); // This is ok. a.a is on a byte bound so we can have a runtime address to it
    _ = @ptrToInt(&a.b); // This should be an error. The address this will return is actually the address to ´a.a´
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions