After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761550 - Cannot build with default flags under Fedora rawhide (-Werror=format-nonliteral)
Cannot build with default flags under Fedora rawhide (-Werror=format-nonliteral)
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: build
unspecified
Other All
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-02-04 12:59 UTC by coypu
Modified: 2016-03-03 15:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
hack patch (557 bytes, patch)
2016-02-04 12:59 UTC, coypu
none Details | Review
Super duper minimal warning avoidance (798 bytes, patch)
2016-02-07 22:12 UTC, coypu
none Details | Review
Changed commit message on patch (903 bytes, patch)
2016-02-08 09:21 UTC, coypu
none Details | Review
Revert previous patch (957 bytes, application/mbox)
2016-03-02 17:56 UTC, coypu
  Details
Same patch but friendly to older GCC (930 bytes, patch)
2016-03-02 17:57 UTC, coypu
none Details | Review

Description coypu 2016-02-04 12:59:28 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
Comment 1 Christian Persch 2016-02-07 16:42:34 UTC
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.)
Comment 2 coypu 2016-02-07 22:12:07 UTC
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"
Comment 3 Colin Walters 2016-02-08 08:41:38 UTC
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
Comment 4 coypu 2016-02-08 09:21:54 UTC
Created attachment 320608 [details] [review]
Changed commit message on patch
Comment 5 Colin Walters 2016-02-08 09:27:45 UTC
Review of attachment 320608 [details] [review]:

Thanks!
Comment 6 Paolo Borelli 2016-02-08 14:34:49 UTC
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
Comment 7 coypu 2016-02-08 14:43:22 UTC
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.
Comment 8 coypu 2016-02-09 17:48:07 UTC
(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.
Comment 9 Paolo Borelli 2016-02-09 17:57:59 UTC
Do not worry, just leave them for now. If the MSVC build break, we'll fix it
Comment 10 coypu 2016-03-02 17:56:48 UTC
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
Comment 11 coypu 2016-03-02 17:57:11 UTC
Created attachment 322896 [details] [review]
Same patch but friendly to older GCC
Comment 12 Colin Walters 2016-03-03 15:56:10 UTC
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