什么是 clang-check 的垃圾值
What's a garbage value for clang-check
我收到以下警告:
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;
});
我收到以下警告:
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;
});