gpt4 book ai didi

c++ - 什么是 clang-check 的垃圾值

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:16:18 24 4
gpt4 key购买 nike

我收到以下警告:

test.cpp:14:25: warning: The right operand of '/' is a garbage value
return (std::abs(a) / size) > 10;
^ ~~~~

对于这段代码:

#include <algorithm>
#include <complex>
#include <vector>
#include <iostream>

using namespace std;
double
pitchDetect(const std::vector<std::complex<double>> &dft,
unsigned int samplingRate) noexcept {
if (dft.empty())
return 0.0;
auto it = find_if(begin(dft), end(dft),
[size = dft.size()](const std::complex<double> &a) {
return (std::abs(a) / size) > 10;
});
return 0.0;
}

我不明白这是什么问题!

最佳答案

这看起来像 bug 22833 ,固定在主干中:

Giving a lambda capture parameter an explicit value (new feature in C++14) causes the analyzer to believe that value is undefined.

作为解决方法,您可以尝试将 init-capture 提升到 lambda 之外:

  auto const size = dft.size();
auto it = find_if(begin(dft), end(dft),
[size](const std::complex<double> &a) {
return (std::abs(a) / size) > 10;
});

关于c++ - 什么是 clang-check 的垃圾值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33923993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com