Correct missing field initializer warning
cover Correct missing field initializer warning
The L_PLUGIN_DEFINE() macro triggered missing field initializer warnings when the corresponding warning flag was enabled for user defined plugins. Prevent ELL from exposing such warnings to the user by explicitly initializing all l_plugin_desc fields, as well re-enabling that warning in maintainer mode builds.
Ossama Othman (2):
plugin: Explicitly initialize descriptor fields. Re-enable -Wmissing-field-initializers warning.
acinclude.m4 | 1 - ell/plugin.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 plugin: Explicitly initialize descriptor fields.
The l_plugin_desc debug_start and debug_stop fields were implicitly initialized in the L_PLUGIN_DEFINE macro. While that is the expected behavior, doing so may trigger a warning about missing field initializers (e.g. when gcc's -Wmissing-field-initializers option is enabled). ELL explicitly disables that warning in maintainer mode builds, but users cannot be expected to disable that warning to silence warnings emanating from their own use of L_PLUGIN_DEFINE. Explicitly initialize the debug_{start,stop} fields to prevent such warnings from being triggered in ELL based user defined plugins.
Alternatively, allowing the two fields in question to be implicitly initialized through designated initialization of the plugin descriptor prevents the missing field initializer warning from being triggered, but it was simpler to explicitly initialize them instead.
--- ell/plugin.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ell/plugin.h +2 -1
@@ -48,7 +48,8 @@ struct l_plugin_desc { extern struct l_plugin_desc symbol \ __attribute__ ((visibility("default"))); \struct l_plugin_desc symbol = { \ - #name, description, version, priority, init, exit \ + #name, description, version, priority, init, exit, \ +NULL ,NULL \ }; #define L_PLUGIN_DEFINE_DEBUG(symbol, name, description, version, \
Signature · 1 line
2.17.1
PATCH 2/2 Re-enable -Wmissing-field-initializers warning.
In reply to Ossama OthmanThe L_PLUGIN_DEFINE() macro was the sole part of ELL that triggered the missing field initializer warning. Now that it no longer triggers that warning drop the -Wno-missing-field-initializers option from the maintainer mode CFLAGS so that exposure of such problems to the user can be prevented in the future.
--- acinclude.m4 | 1 - 1 file changed, 1 deletion(-)
acinclude.m4 +0 -1
@@ -54,7 +54,6 @@ AC_DEFUN([COMPILER_FLAGS], [ if (test "$USE_MAINTAINER_MODE" = "yes"); then CFLAGS+=" -Werror -Wextra" CFLAGS+=" -Wno-unused-parameter" - CFLAGS+=" -Wno-missing-field-initializers" CFLAGS+=" -Wdeclaration-after-statement" CFLAGS+=" -Wmissing-declarations" CFLAGS+=" -Wredundant-decls"
Signature · 1 line
2.17.1
Hi Ossama,
Quoted 6 lines · Ossama Othman
The
L_PLUGIN_DEFINE()macro triggered missing field initializer warnings when the corresponding warning flag was enabled for user defined plugins. Prevent ELL from exposing such warnings to the user by explicitly initializing alll_plugin_descfields, as well re-enabling that warning in maintainer mode builds.
Quoted 8 lines
Ossama Othman (2):
plugin: Explicitly initialize descriptor fields. Re-enable -Wmissing-field-initializers warning.acinclude.m4 | 1 - ell/plugin.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
Both applied, thanks.
Regards,
-Denis