[PATCH 26/59] stdio: Fix -Wtautological-constant-out-of-range-compare on clang

Collin Funk collin.funk1@gmail.com
Fri Oct 17 20:10:59 GMT 2025


Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:

> clang emits an error while building vfprintf-internal for default
> case:
>
> error: result of comparison of constant 255 with expression of type
> 'char' is always true
> [-Werror,-Wtautological-constant-out-of-range-compare]
>           if (spec <= UCHAR_MAX
>
> The test is indeed not required for default non-wide build.
> ---
>  stdio-common/vfprintf-internal.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
> index fa41e1b242..2238137d6d 100644
> --- a/stdio-common/vfprintf-internal.c
> +++ b/stdio-common/vfprintf-internal.c
> @@ -1337,7 +1337,12 @@ printf_positional (struct Xprintf_buffer * buf, const CHAR_T *format,
>        /* Process format specifiers.  */
>        do
>  	{
> -	  if (spec <= UCHAR_MAX
> +# ifdef COMPILE_WPRINTF
> +#  define CHECK_SPEC(spec) ((spec) <= UCHAR_MAX)
> +# else
> +#  define CHECK_SPEC(spec) (true)
> +# endif
> +	  if (CHECK_SPEC (spec)
>  	      && __printf_function_table != NULL
>  	      && __printf_function_table[(size_t) spec] != NULL)
>  	    {

Can we just disable this warning? Anecdotally, it is only triggered in
Gnulib in code that is needed for portability. I can't recall a time
where I found it useful.

Collin


More information about the Libc-alpha mailing list