小编Ric*_*ski的帖子

std::accumulate 溢出警告

init当arg 的类型与您正在累积的包含类型不匹配时,是否有任何方法可以收到 std::accumulate 警告?例如,在此示例中,我们在迭代 64 位整数向量时不应累积 32 位值。但是很容易只传入 0 而忘记传递 0LL。有什么办法可以得到警告吗?-Wall -Wextra -Wconversion似乎没有帮助。我还尝试寻找可能有效的 clang tidy 检查,但也没有找到任何东西。

std::vector<long long> a = {10000000000, 10000000000};
cout << std::accumulate(a.begin(), a.end(), 0) << "\n"; // overflows
cout << std::accumulate(a.begin(), a.end(), 0LL) << "\n"; // prints 20000000000
Run Code Online (Sandbox Code Playgroud)

c++ warnings clang-tidy

10
推荐指数
1
解决办法
231
查看次数

标签 统计

c++ ×1

clang-tidy ×1

warnings ×1