Conversation
chfast
left a comment
There was a problem hiding this comment.
So you think this is a false positive warning?
| return std::nullopt; | ||
| } | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Warray-bounds" |
There was a problem hiding this comment.
is this still needed given the if-check above?
There was a problem hiding this comment.
is this still needed given the if-check above?
The error is still emitted unfortunately even with the check.
There was a problem hiding this comment.
could you clarify the error? how does a big number like "576460752303423485" or "9223372036854775760" end up there despite the check? who is passing that number? could it be that if is faulty due to some signed-unsigned UB?
There was a problem hiding this comment.
I don't know where this number comes from (it's some internal details of the array-bounds check in gcc). The comparison is fine (both arguments are of type size_t).
There was a problem hiding this comment.
This warning comes from optimized GCC builds. After some optimizations related to inlining and constant propagation compiler can convince itself that it knows the access index of an array and compare it with the array size.
Unfortunately, this analysis is known to have false-positives, see e.g.
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100038
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107699
If we want to be nice and you think it is worth the time I can reduce this example and report an issue. Or I can make a tutorial how to reduce failing compilations.
Yes, I think so |
Address the following error when compling with gcc 14.2: