* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
@ 2012-04-07 20:42 ` manu at gcc dot gnu.org
2012-04-23 19:58 ` joseph at codesourcery dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-07 20:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |joseph at codesourcery dot
| |com, manu at gcc dot
| |gnu.org
--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-07 20:42:23 UTC ---
Joseph, do we want to do this or not? We could always move -Wformat-zero-length
to -Wformat=2 or to -Wextra (or both)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
2012-04-07 20:42 ` [Bug c/47901] " manu at gcc dot gnu.org
@ 2012-04-23 19:58 ` joseph at codesourcery dot com
2012-04-23 20:08 ` manu at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: joseph at codesourcery dot com @ 2012-04-23 19:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-04-23 19:58:15 UTC ---
There are plenty of warnings in -Wall that relate to things that are
unusual but may be OK in some cases, or where -Wall expects a particular
coding style to be used. I think -Wformat-zero-length falls into the
category of pointing out something that might be OK but is likely not to
be intended. So I think it's fine in -Wall - but if a subset of format
checking warnings were enabled by default (as in Ubuntu, for example) then
maybe that default subset would not include this one.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
2012-04-07 20:42 ` [Bug c/47901] " manu at gcc dot gnu.org
2012-04-23 19:58 ` joseph at codesourcery dot com
@ 2012-04-23 20:08 ` manu at gcc dot gnu.org
2012-04-23 20:11 ` andersk at mit dot edu
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-23 20:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-23 20:08:09 UTC ---
Well, I don't really see how custom_printf("") can produce any damage. It may
be an oversight when one actually wanted to print something, but it may be as
likely that one didn't want to print something and just trigger some side
effect of custom_printf.
As an alternative, the warning could suggest to use ("%s", "") to silence the
warning, no?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (2 preceding siblings ...)
2012-04-23 20:08 ` manu at gcc dot gnu.org
@ 2012-04-23 20:11 ` andersk at mit dot edu
2012-04-23 20:22 ` andersk at mit dot edu
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: andersk at mit dot edu @ 2012-04-23 20:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #4 from Anders Kaseorg <andersk at mit dot edu> 2012-04-23 20:10:22 UTC ---
Yes, I understand what -Wall is supposed to mean.
I don’t have a problem with -Wall warning about ‘if (foo = 3)’ when I probably
intended ‘if (foo == 3)’ and I could have written ‘if ((foo = 3))’ if that’s
what I really wanted.
I don’t have a problem with -Wall warning about ‘printf("hello", "world")’ when
I probably intended ‘printf("hello %s", "world")’ and I could have written
‘printf("hello")’ if that’s what I really wanted.
But ‘custom_printf_like_function(foo, "")’ is something different. What do you
think that line indicates I intended? What coding style do you think -Wall is
expecting if I really meant the empty string?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (3 preceding siblings ...)
2012-04-23 20:11 ` andersk at mit dot edu
@ 2012-04-23 20:22 ` andersk at mit dot edu
2012-04-23 20:50 ` joseph at codesourcery dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: andersk at mit dot edu @ 2012-04-23 20:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #5 from Anders Kaseorg <andersk at mit dot edu> 2012-04-23 20:22:20 UTC ---
I’m not sure ("%s", "") is a suitable replacement in general. Maybe this is a
far-fetched example, but what the purpose of custom_printf is to shell-quote
all its arguments, so that custom_printf(foo, "") writes "some_command" with no
arguments but custom_printf(foo, "%s", "") writes "some_command ''" with a
single empty argument?
In any event, ("%s", "") is certainly different code with a potential runtime
cost, and it’s not fair for -Wall to complain about the more straightforward
("") unless it’s reasonably likely for that code to be hiding some class of
bugs. Is it?
(Another real-world example from a project I help maintain:
https://github.com/barnowl/barnowl/blob/barnowl-1.8.1/keys.c#L337 )
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (4 preceding siblings ...)
2012-04-23 20:22 ` andersk at mit dot edu
@ 2012-04-23 20:50 ` joseph at codesourcery dot com
2012-04-23 21:31 ` andersk at mit dot edu
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: joseph at codesourcery dot com @ 2012-04-23 20:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #6 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-04-23 20:49:38 UTC ---
-Wall is expecting printf-like functions where empty strings are useless
as arguments and might indicate e.g. cruft you hadn't completely cleaned
up from your program. Or a style where you have separate specialized
functions for such cases (like the style where you carefully use fputs,
fputc etc. for cases that can be covered by those functions, instead of
using printf universally).
There's nothing wrong with using a -Wno- option (or associated pragmas) if
the stylistic choices for your program are different from those for -Wall.
Wall tries to strike a reasonable balance, but won't be perfect for
everyone; it's a good starting point for both enabling further warnings,
and disabling other warnings, to taste.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (5 preceding siblings ...)
2012-04-23 20:50 ` joseph at codesourcery dot com
@ 2012-04-23 21:31 ` andersk at mit dot edu
2012-04-26 14:19 ` manu at gcc dot gnu.org
2013-12-21 20:01 ` naesten at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: andersk at mit dot edu @ 2012-04-23 21:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #7 from Anders Kaseorg <andersk at mit dot edu> 2012-04-23 21:31:18 UTC ---
That’s a _much_ higher-level style decision than assumed by any of the other
-Wall warnings (or indeed any other warning switches at all), and a
questionable one at that. -Wall should not encourage me to duplicate all my
custom printf-like functions just so they can be used with the empty string.
I understand that I can turn this warning off, but this bug is about the
defaults, and defaults are important.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (6 preceding siblings ...)
2012-04-23 21:31 ` andersk at mit dot edu
@ 2012-04-26 14:19 ` manu at gcc dot gnu.org
2013-12-21 20:01 ` naesten at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-26 14:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-26 14:19:13 UTC ---
I still think it may be fine moving this warning to -Wextra, since it gives
false positives and when it does, they are hard to avoid.
Anders, you may get to convince more people by sending a patch to gcc-patches
with your reasoning.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/47901] -Wall should not imply -Wformat-zero-length by default
2011-02-26 9:11 [Bug c/47901] New: -Wall should not imply -Wformat-zero-length by default anders at kaseorg dot com
` (7 preceding siblings ...)
2012-04-26 14:19 ` manu at gcc dot gnu.org
@ 2013-12-21 20:01 ` naesten at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: naesten at gmail dot com @ 2013-12-21 20:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47901
Samuel Bronson <naesten at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |naesten at gmail dot com
--- Comment #9 from Samuel Bronson <naesten at gmail dot com> ---
Wouldn't the case where a given custom printf-like function does more than just
print the formatted text be better solved by adding a new __attribute__ to
disable this warning for such a function? (Assuming anyone actually wants
these warnings ever ...)
Then, you could still have warnings for code like 'printf();' that does
nothing, while avoiding them for your 'custom_printf(foo, "");' that does do
something.
^ permalink raw reply [flat|nested] 10+ messages in thread