Bruno Haible <[email protected]> writes:
> Paul Eggert wrote:
>> > It is a bit unfortunate that this warning comes up almost monthly
>>
>> Perhaps we should add something like the following to
>> gnulib/lib/gettext.h, once we have a Clang bug report number?
>> Although drastic, this would save us time and we'd still get static
>> checking when compiling with GCC, except for printf calls in
>> clang-only code (which should be rare).
>>
>> /* Pacify clang false alarm
>> <https://github.com/llvm/llvm-project/issues/987654321>. */
>> #ifdef __clang__
>> # pragma clang diagnostic ignored "-Wformat-security"
>> #endif
>
> Nice idea. But I still [1] think that it is too drastic. Some people
> might be really upset.
Yes, it is probably a bit excessive. The warning is generally helpful
outside of this specific instance.
I was preparing a bug report for Clang, and think I found out how to fix
the issue. See the following program:
$ cat example.c
#include <stdio.h>
#include <stdlib.h>
#ifdef ENABLE_NLS
# include <libintl.h>
#else
__attribute__ ((__always_inline__, __gnu_inline__,
__format_arg__ (1)))
extern inline char const *
gettext (const char *msgid)
{
return msgid;
}
#endif
#define _(msgid) gettext (msgid)
int
main (void)
{
/* No warning. */
printf (_("Hello, %s!\n"), "world");
/* Warning. */
printf (_("Hello, world!\n"));
return EXIT_SUCCESS;
}
$ clang -Wformat-security example.c
So, adding "__format_arg__ (1)" in this instance will silence it.
If that sounds okay, I'll figure out what version of GCC and Clang added
them and submit a patch.
Collin