[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: warnings in dead code
From: |
Bruno Haible |
Subject: |
Re: warnings in dead code |
Date: |
Sun, 12 Feb 2017 12:57:18 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-62-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote in
https://lists.gnu.org/archive/html/bug-gnulib/2017-01/msg00145.html:
>
> short bar = -32768 <= 100000 && 100000 <= 32767 ? (short) 100000 : 0;
>
> Although this is valid C code and is well-defined to initialize 'bar' to
> 0 on x86-64, pgcc warns "Constant value out of range for signed short or
> char". Since the expression "(short) 100000" is not evaluated, the
> warning is bogus. ...
>
> Admittedly these warnings are annoying. Adam, since you're a PGI user,
> perhaps you could report the compiler bug or bugs to the PGI maintainers.
GCC also emits warnings for dead code. Like here (seen in test-strtol.c):
=========================== foo.c ===========================
#include <errno.h>
#include <stdlib.h>
int
main ()
{
if (sizeof (long) > sizeof (int))
{
const char input[] = "4294967295";
char *ptr;
long result;
errno = 0;
result = strtol (input, &ptr, 10);
if (!(result == 65535L * 65537L)) abort ();
if (!(ptr == input + 10)) abort ();
if (!(errno == 0)) abort ();
}
return 0;
}
=============================================================
$ gcc -m32 -O -Wall foo.c
foo.c: In function ‘main’:
foo.c:14:30: warning: integer overflow in expression [-Woverflow]
if (!(result == 65535L * 65537L)) abort ();
^
$ gcc -v
...
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
Should we report it as a GCC bug?
Bruno
- Re: warnings in dead code,
Bruno Haible <=