[Bug c/80354] Poor support to silence -Wformat-truncation=1
sbergman at redhat dot com
gcc-bugzilla@gcc.gnu.org
Mon Apr 10 07:20:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80354
--- Comment #2 from Stephan Bergmann <sbergman at redhat dot com> ---
But that makes this warning extremely hard to use. Is it really useful for
-Wall in that case?
I came across this with a real-world use-case in the LibreOffice code base,
where some code deliberately uses snprintf to produce a fixed-size prefix, see
<https://gerrit.libreoffice.org/#/c/36211/> "WaE: ‘%lu’ directive output may be
truncated". (And older builds of GCC towards GCC 7 did not emit that unhelpful
warning with -Wall => -Wformat-truncation=1, but would only have emitted it
with an explicit -Wformat-truncation=2.)
Addressing false positives for this warning thus becomes an unpleasant
whack-a-mole (given different builds of the code are done with different
optimization switches), unpleasant enough so that we'll likely have to use
-Wall -Wformat-truncation=0 for LibreOffice. Which is unfortunate, given that
casting-to-void would be a well-understood and well-accepted way to silence
false positives (but one hard to implement in GCC, if I understand you
correctly).
More information about the Gcc-bugs
mailing list