Skip to content
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

Building a project which uses json-c with flag -Wcast-qual causes compilation errors #236

Closed
svagionitis opened this issue Jun 9, 2016 · 2 comments
Labels

Comments

@svagionitis
Copy link

I use json-c in one project which one of the compiler flags is -Wcast-qual. I use the macro json_object_object_foreach and I get the following error when compiling

error: cast from 'const void *' to 'struct json_object *' drops const qualifier [-Werror,-Wcast-qual]
    json_object_object_foreach(body_json, key, val)
    ^
/usr/include/json-c/json_object.h:320:31: note: expanded from macro 'json_object_object_foreach'
                        val = (struct json_object*)entry ## key->v; \
                                                   ^

This happens because the value, in the lh_entry, is set as const but in the macro json_object_object_foreach the value is type casted as non-const.

Now, removing the const qualifier from the value in lh_entry fixes the issue, but I am not familiar with the json-c code base and I don't think that might be the proper solution.

@hawicz
Copy link
Member

hawicz commented Jun 11, 2016

No, the const should stay there. I've got some changes that should improve the situation, which I'll be pushing shortly.

hawicz added a commit that referenced this issue Jun 11, 2016
To better distinguish between entry->k and entry->v being const within linkhash, but non-const outside, add lh_entry_v() and lh_entry_k() accessors.
Make lh_entry->k const.
@hawicz hawicz closed this as completed Jun 11, 2016
@hawicz hawicz added the bug label Jun 11, 2016
@svagionitis
Copy link
Author

Cool, thanks @hawicz for your quick reply and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants