This is the mail archive of the gcc-patches@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: "format not a string literal"


Ken Raeburn <raeburn@raeburn.org> writes:

> Current versions of gcc can retain the __builtin_constant_p test
> inside an inline function.  If you change gettext to be an inline
> function (at least for gcc 2.96 and later), you'll get the format
> checking back and this warning should go away (since the compiler
> knows about a function named "gettext" but not a macro by that name),
> and you shouldn't lose any of the performance.

But the __builtin_constant_p in dcgettext will not work.  That's the
whole purpose.  Read the comments in libintl.h.

> Otherwise, we should probably make sure that people know that -Wformat
> is useless when GNU gettext is involved.

It's not useless because a) if you compile without optimization you'll
get the warnings and b) this expression will change.  It predates any
gcc support.

But this does not change the fact that now with this change flawless
code produces tons of warnings.  Unjustified.

> I certainly wouldn't have guessed that that was the case, and I'd
> consider it a bug -- not necessarily a bug in gettext, but a bug
> that's far, far easier to address by tweaking gettext.

The code is just fine and there are several other cases which now
fail.  E.g., one frequent case is:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>

void
foo (int n)
{
  printf (n == 1 ? "%d file" : "%d files", n);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(I know this is not really good from i18n perspective, it's still used
quite often).  Or getting a string from an array of format strings.
This all produces the same warning.  Not every use of printf-like
functions is as unsophisticated as the ones you have in your code.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------


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