加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – clang-check的垃圾值是多少

发布时间:2020-12-16 07:14:32 所属栏目:百科 来源:网络整理
导读:我收到了以下警告: 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 iostreamusing namespace std;doublepitch
我收到了以下警告:

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,固定在trunk中:

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

作为一种解决方法,您可以尝试在lambda外部提升init-capture:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读