This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: -Wformat warnings


"Kaveh R. Ghazi" wrote:
> 
>  > From: Martin Buchholz <martin@xemacs.org>
>  >
>  > The -Wformat warnings are nice, but how does one turn them off when
>  > the format string arg is non-constant?  In my opinion, the following
>  > warning should never appear - it's a useless meta-warning.  There
>  > doesn't seem to be an obvious way to suppress them.
>  >
>  > /xemacs/ws/dev/src/lread.c:312: warning: format not a string
>  >      literal, argument types not checked
>  >
>  > It would be nice if warnings could be properly done for this:
>  >
>  >           fprintf (stderr,
>  >                    (c >= 0x20 && c <= 0x7E) ? "UU%c" :
>  >                    ((c == '\n') ? "UU\\n\n" : "UU\\%o"), c);
>  >
> 
> Yes many people have complained about this.

Yup.  The unique thing about this warning is that there are valid
circumstances under which it's _impossible_ to remove it.  Kinda
devalues -Werror, no?

> ...
> 
> Anyway, no one has stepped up to the plate and provided a way to turn
> it off independent of -Wformat.  But I expect there to be one before
> the next official release.

Here's my proposal:

Change the warn() function so that it recognises sentinels in the format
string.  So this:

	warn("format not a string literal...")

becomes

	warn("~format-not-literal~format not a string literal...")

Then accept command line switches of the form:

	-W-format-not-literal

to suppress this warning.  All worked out at runtime: the warn()
function would have to run through the list of "-W-" arguments prior to
generating the warning.

* It's seamless: it is not required that _all_ instances of warn() be
changed on day one.

* Could be extended to allow/suppress -Werror on particular warnings
rather than on all of them.

* Documentation can be easily extracted direct from the source tree.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]