[Bug c++/78130] New: Strict overflow warning appears to be invalid
rianquinn at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 27 13:32:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78130
Bug ID: 78130
Summary: Strict overflow warning appears to be invalid
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rianquinn at gmail dot com
Target Milestone: ---
Currently bounds checks inside Microsoft's GSL are causing a strict overflow
warning to trigger that appears to be invalid (i.e. the bounds checks should be
fine). The issue has been documented here:
https://github.com/Microsoft/GSL/pull/405
The bounds check looks like this (both count and size() are std::ptrdiff_t):
Expects(count >= 0 && count <= size());
The code can be seen here:
https://github.com/Microsoft/GSL/blob/master/gsl/span#L475
The warning is the following:
warning: assuming signed overflow does not occur when assuming
that (X - c) > X is always false [-Wstrict-overflow]
And the warning occurs on both GCC 5 and 6. Simplifying the code still
generates the warning:
Expects(count >= 0); // fine
Expects(count <= size()); // Generates warning
Doing the following fixes the issue, but is obviously less than ideal:
Expects(count >= 0 && (count < size() || count == size()));
More information about the Gcc-bugs
mailing list