Skip to content

translate-c: casting away const fails #4044

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
tadeokondrak opened this issue Jan 2, 2020 · 1 comment · Fixed by #4052
Closed

translate-c: casting away const fails #4044

tadeokondrak opened this issue Jan 2, 2020 · 1 comment · Fixed by #4052
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@tadeokondrak
Copy link
Contributor

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.

@andrewrk andrewrk added this to the 0.7.0 milestone Jan 2, 2020
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport) labels Jan 2, 2020
@andrewrk
Copy link
Member

andrewrk commented Jan 2, 2020

Related: it will be nice to have test coverage for these kinds of bugs with #4018.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants