C++ 什么';这是一个用于叮当声检查的垃圾值
我得到以下警告:C++ 什么';这是一个用于叮当声检查的垃圾值,c++,c++14,clang-static-analyzer,C++,C++14,Clang Static Analyzer,我得到以下警告: 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 <io
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;
}
#包括
#包括
#包括
#包括
使用名称空间std;
双重的
pitchDetect(常数标准::矢量和dft,
无符号整数采样)无例外{
if(dft.empty())
返回0.0;
自动it=查找if(开始(dft),结束(dft),
[size=dft.size()](常量std::complex&a){
返回(标准::abs(a)/尺寸)>10;
});
返回0.0;
}
我不明白是什么问题 这看起来像是固定在主干中的:
给lambda capture参数一个显式值(C++14中的新特性)会使分析器认为该值未定义
作为一种解决方法,您可以尝试将init捕获提升到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;
});
auto const size=dft.size();
自动it=查找if(开始(dft),结束(dft),
[尺寸](常数标准::复杂&a){
返回(标准::abs(a)/尺寸)>10;
});