GNOME Bugzilla – Bug 761550
Cannot build with default flags under Fedora rawhide (-Werror=format-nonliteral)
Last modified: 2016-03-03 15:56:10 UTC
Created attachment 320428 [details] [review] hack patch gdate.c: In function ‘g_date_strftime’: gdate.c:2497:7: error: format not a string literal, format string not checked [-Werror=format-nonliteral] tmplen = strftime (tmpbuf, tmpbufsize, locale_format, &tm); ^~~~~~ cc1: some warnings being treated as errors Solved by dirty hack attached: #pragma GCC diagnostic ignored "-Wformat-nonliteral" Seems like it is done elsewhere in glib, too. Same bug report as http://gnats.netbsd.org/50753
You shouldn't just ignore the warning for the whole file, but use '#pragma GCC diagnostic push' before the '#pragma GCC diagnostic ignored "-Wformat-nonliteral"', and '#pragma GCC diagnostic pop' afterwards, and put this only around the one place where this warning needs to be silenced. (Assuming the code can't be rewritten to actually make the format a literal.)
Created attachment 320586 [details] [review] Super duper minimal warning avoidance > Assuming the code can't be rewritten to actually make the format a literal $ grep -Ri 'Wformat-nonliteral' . ./glib/gdate.c: #pragma GCC diagnostic ignored "-Wformat-nonliteral" ./glib/gfileutils.c:#pragma GCC diagnostic ignored "-Wformat-nonliteral" ./glib/gmarkup.c:#pragma GCC diagnostic ignored "-Wformat-nonliteral" ./glib/gstrfuncs.c:#pragma GCC diagnostic ignored "-Wformat-nonliteral" ./glib/gutils.c:#pragma GCC diagnostic ignored "-Wformat-nonliteral" ./glib/tests/test-printf.c:#pragma GCC diagnostic ignored "-Wformat-nonliteral"
Review of attachment 320586 [details] [review]: Hi, the patch looks fine, but could you enhance the commit message a bit? See https://wiki.gnome.org/Newcomers/SubmittingPatches Something like: gdate: Suppress string format literal warning Newer versions of GCC emit a warning here, but we know it's safe. https://bugzilla.gnome.org/761550
Created attachment 320608 [details] [review] Changed commit message on patch
Review of attachment 320608 [details] [review]: Thanks!
Should probably be ifdeffed though, shouldn't it? I guess we do not want those pragmas with MSVC or maybe even with older versions of gcc
It became a flag probably because of a change of default flags I had the same error by using -Wformat-nonliteral on GCC 4.8.5.
(In reply to Paolo Borelli from comment #6) > Should probably be ifdeffed though, shouldn't it? I guess we do not want > those pragmas with MSVC or maybe even with older versions of gcc Should I perform more changes? Other uses of this in the code (e.g. glib/gutils.c:2087) are not ifdef'd. I figure MSVC is ignoring them.
Do not worry, just leave them for now. If the MSVC build break, we'll fix it
Created attachment 322895 [details] Revert previous patch Really sorry for the trouble, it DOES break older GCC versions, as late as 4.5 This is important because glib2 is used by pkg-config and this unneeded brokenness causes a lot of fallout: http://mail-index.netbsd.org/pkgsrc-bulk/2016/03/02/msg012472.html This is a problem for LTS operating systems (NetBSD 6.1.5)/rarely updated ones and a few esoteric ones that chose pre-GPLv3 GCC (OpenBSD). Used more standard style used elsewhere too
Created attachment 322896 [details] [review] Same patch but friendly to older GCC
Thanks for the updated patches, though I squashed these two into one commit which I think is simpler: https://git.gnome.org/browse/glib/commit/?id=8cdbc7fb2c8c876902e457abe46ee18a0b134486