The following code (reduced from a larger, more sensible sample):
#include <vector>
void shrink(std::vector<int>& v) {
while (v.size() > 0) {
v.resize(v.size() - 1);
}
}
Leads gcc 7.3 to emit this warning (godbolt):
In function 'void shrink(std::vector<int>&)':
cc1plus: warning: 'void* __builtin_memset(void*, int, long unsigned int)':
specified size 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
I have been staring at this code for close to an hour with a colleague, and it just seems correct to me; what is gcc complaining about?
it just seems correct to me
The example is correct.
what is gcc complaining about?
This is a compiler bug. Here is the bugzilla. The bug appears to be fixed in GCC 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With