Skip to content

translate-c: casting away const fails #4044

Closed
@tadeokondrak

Description

@tadeokondrak
static void function2(int *a) {
	const int *b = a;
}

static void function(const int *a) {
	function2((int *)a);
}
const a: c_int = 0;
function(&a);
/home/tdeo/.cache/zig/stage1/o/.../cimport.zig:7:15: error: cast discards const qualifier
    function2(@ptrCast([*c]c_int, @alignCast(@alignOf(c_int), a)));

Motivation: Wayland add_listener functions cast their struct of function pointer arguments to void (**)(void) before passing them to another function, which then stores it in a const field and never modifies through it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.translate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions