[cfe-commits] [Patch] Warn about non-standard format strings (PR12017)
kremenek at apple.com
Mon Feb 20 13:02:25 CST 2012
Thanks so much for working on this, but I'm honestly *very* concerned about the practicality of issuing all these warnings. Real code makes assumptions on what format specifiers are available given the platform(s) they are targeting. Unconditionally warning about non-standard stuff seems like a recipe to irritate a huge number of users. Indeed, the format string checking now relaxes the strict interpretation of the standard in cases where it's basically always safe. This is the behavior users expect. I think it's also important to keep in mind the purpose of these warnings. The purpose of these warnings is to find problems, not annoy users.
For me, the better approach would be two options:
(1) Warn about non-standard format strings only when it is an issue for the target platform. This is hard to do, but this is basically what users will expect.
(2) Provide an opt-in mechanism for such pedantic warnings. For example, activating these warnings under -pedantic, or simply requiring them to pass -Wformat-nonstandard. This will satisfy users who care about portability.
I definitely think that -Wformat-nonstandard should not be on by default, and not activated by passing -Wformat.
Concerning (2), there may just be an option question about warnings concerning non-portable code. That's a wide open topic, but checking for non-standard format specifiers is really just one drop in that bucket. It may be worth having a cohesive plan for just checking for non-portable stuff, and maybe grouping them under something like "-Wportable".
On Feb 20, 2012, at 10:31 AM, Hans Wennborg <hans at chromium.org> wrote:
> Hi all,
> Attached is a first stab at adding a warning for using non-standard
> things in format strings (like the 'q' length modifier or the 'S'
> conversion specifier).
> I'm a little bit confused about the status of some of these. For
> example, should 'C' and 'S' be considered GNU extensions, and
> therefore allowable when using -std=gnu99?
> Also, there might be a better approach to this, or better names for
> things, etc. so please take a look.
> This causes a bunch of new failures in the gcc.dg test-suite. For
> instance, in gcc.dg/format/c90-scanf-3.c it will warn about the 'a'
> length modifier. The test says "Formats using extensions to the
> standard should be rejected in strict pedantic mode." so I think my
> patch is doing the right thing, but maybe the expectations need to be
> tweaked a bit.
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
More information about the cfe-commits