2015-11-25 45 views
3

我有以下警告:什麼是垃圾值鐺檢查

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; 
} 

我不明白是什麼問題!

回答

1

這看起來像bug 22833,其固定在軀幹:

給予一個lambda捕獲參數的顯式值(新特徵在C++ 14)使得分析器相信值是未定義的。

作爲一種變通方法,你可以嘗試衝頂拉姆達外初始化捕獲:

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; 
    });