GNOME Bugzilla – Bug 752288
value in values: Params of the search function should be const
Last modified: 2018-05-22 15:25:04 UTC
To compile this vala code: if (value in values) where value is a string and values a string[], valac generated a function whose prototype is: static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle); but the values it passes to the needle params is contant, and hence I got this error: variable/Options.c: In function 'retro_option_set_current': variable/Options.c:272:59: warning: passing argument 3 of '_vala_string_array_contains' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] if (_vala_string_array_contains (_tmp1_, _tmp1__length1, _tmp0_)) { ^ variable/Options.c:253:17: note: expected 'gchar * {aka char *}' but argument is of type 'const gchar * {aka const char *}' static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle) { ^ I would suggest to make the stack and needle parameters constant as they are never changed by the function.
Created attachment 314428 [details] [review] Use const pointers for the needle parameters in array_contains functions Seems like using a const pointer for the needle is always fine, at least considering the generated type, which is also const. The stack however is not const when generated so that might need further changes.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/504.