[Bug c++/88680] [9 Regression] bogus -Wtype-limits for constant expressions after r267272
dmalcolm at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Feb 16 16:17:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88680
--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Author: dmalcolm
Date: Sat Feb 16 16:17:17 2019
New Revision: 268961
URL: https://gcc.gnu.org/viewcvs?rev=268961&root=gcc&view=rev
Log:
Fix excess warnings from -Wtype-limits with location wrappers (PR c++/88680)
PR c++/88680 reports excess warnings from -Wtype-limits after the C++
FE's use of location wrappers was extended in r267272 for cases such as:
const unsigned n = 8;
static_assert (n >= 0 && n % 2 == 0, "");
t.C:3:18: warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
3 | static_assert (n >= 0 && n % 2 == 0, "");
| ~~^~~~
The root cause is that the location wrapper around "n" breaks the
suppression of the warning for the "if OP0 is a constant that is >= 0"
case.
This patch fixes it by calling fold_for_warn on OP0, extracting the
constant.
gcc/c-family/ChangeLog:
PR c++/88680
* c-common.c (shorten_compare): Call fold_for_warn on op0 when
implementing -Wtype-limits.
gcc/testsuite/ChangeLog:
PR c++/88680
* g++.dg/wrappers/pr88680.C: New test.
Added:
trunk/gcc/testsuite/g++.dg/wrappers/pr88680.C
Modified:
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.c
trunk/gcc/testsuite/ChangeLog
More information about the Gcc-bugs
mailing list