简体   繁体   English

gcc -Wstringop-overflow 在这里抱怨什么?

[英]What is gcc -Wstringop-overflow complaining about here?

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 ):导致 gcc 7.3 发出此警告( 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? gcc 在抱怨什么?

it just seems correct to me这对我来说似乎是正确的

The example is correct.这个例子是正确的。

what is gcc complaining about? gcc 在抱怨什么?

This is a compiler bug.这是一个编译器错误。 Here is the bugzilla .这是bugzilla The bug appears to be fixed in GCC 8.该错误似乎已在 GCC 8 中修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义 fmt::formatter 中的 -Wstringop-overflow 编译器警告<std::bitset<n> > 专业化</std::bitset<n> - -Wstringop-overflow compiler warning in custom fmt::formatter<std::bitset<N>> specialization gcc-8 -Wstringop-truncation 什么是好的做法? - gcc-8 -Wstringop-truncation what is the good practice? 即使有要求,为什么 gcc 也不会抱怨数组边界? - Why isn't gcc complaining about array bounds even if requested? 无法理解链接器在抱怨什么 - Cannot understand what linker is complaining about Cygwin gcc编译在IDE中失败,抱怨未声明“退出” - Cygwin gcc compiled fails in IDE complaining about 'exit' undeclared 什么是这个奇怪的复制构造错误抱怨? - What is this strange copy constructor error complaining about? 不确定编译器在抱怨什么,以及如何找到解决方案 - Not sure what Compiler is complaining about, and how to find the solution OS X上的Eclipse CDT抱怨gcc内置函数:“函数&#39;__builtin_bzero&#39;无法解析” - Eclipse CDT on OS X complaining about gcc built-in function: “Function '__builtin_bzero' could not be resolved” GCC -lm -lz -lrt选项 - 它们是关于什么的? - GCC -lm -lz -lrt options - what are they about? 什么是gcc在这里每个线程运行一次这个代码? - What is gcc doing here to run this code once per thread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM