简体   繁体   English

Eigen LinSpaced - 不推荐使用的复制警告

[英]Eigen LinSpaced - deprecated-copy warning

In my project, compiler complains on the following (and many other similar) code snippets:在我的项目中,编译器抱怨以下(以及许多其他类似的)代码片段:

    Eigen::ArrayXf window =
            Eigen::ArrayXf::LinSpaced(2*M + 1, 0, M_PI)
            .head(2*M)
            .sin();

The warning message is long and unreadable so I will not post all of them here.警告信息很长且无法阅读,因此我不会在此处发布所有内容。 The warning triggered is -Wdeprecated-copy , and the core part of warning message (in my opinion) is in follow触发的警告是-Wdeprecated-copy ,警告消息的核心部分(在我看来)如下

warning: implicitly-declared ‘Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::linspaced_op<float, __vector(4) float>, Eigen::Array<float, -1, 1> >, -1, 1, false>::Block(const Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::linspaced_op<float, __vector(4) float>, Eigen::Array<float, -1, 1> >, -1, 1, false>&)’ is deprecated [-Wdeprecated-copy]
note: because ‘Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::linspaced_op<float, __vector(4) float>, Eigen::Array<float, -1, 1> >, -1, 1, false>’ has user-provided ‘Eigen::BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Eigen::Dense>& Eigen::BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Eigen::Dense>::operator=(const Eigen::BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Eigen::Dense>&) [with XprType = const Eigen::CwiseNullaryOp<Eigen::internal::linspaced_op<float, __vector(4) float>, Eigen::Array<float, -1, 1> >; int BlockRows = -1; int BlockCols = 1; bool InnerPanel = false]’
  830 |     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
      |                                                    ^~~~~~~~
/somewhere/Eigen/src/Core/util/Macros.h:842:53: note: in expansion of macro ‘EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR’
  842 | #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/somewhere/Eigen/src/Core/Block.h:161:5: note: in expansion of macro ‘EIGEN_INHERIT_ASSIGNMENT_OPERATORS’
  161 |     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)

Does this warning lead to an incorrect(unexpected) result?此警告是否会导致不正确(意外)的结果? How can I correct my code to eliminate this warning?如何更正我的代码以消除此警告?

This is a deprecation warning with respect to the C++ standard.这是关于 C++ 标准的弃用警告。

Currently the copy constructor is implicitly defined even if a class has a user-provided destructor or user-provided copy assignment operator.目前,即使类具有用户提供的析构函数或用户提供的复制赋值运算符,复制构造函数也是隐式定义的。

The message is a warning that the current C++ standard (since C++11) deprecates this behavior and that it will be removed from C++ in a future version.该消息是一个警告,表明当前的 C++ 标准(自 C++11 起)不赞成这种行为,并且它将在未来版本中从 C++ 中删除。 It indicates that the programmer should implement or default the copy constructor manually, so that the intended change in a future C++ version will not cause trouble when transitioning.它表示程序员应该手动实现或默认复制构造函数,以便未来 C++ 版本中的预期更改不会在转换时造成麻烦。

It is also a violation of the rule of 0/3/5 not to do so.不这样做也是违反0/3/5规则的 But that rule is only a general guideline and does not need to always apply if the programmer knows what they are doing.但该规则只是一般准则,如果程序员知道他们在做什么,则不需要始终适用。 It is (currently) not enforced by the language.它(当前)没有被语言强制执行。


Since this warning is for library code, not your own, and it is unlikely that the library authors failed to implement all their classes correctly, I would not be concerned by it.由于这个警告是针对库代码的,而不是你自己的,而且库作者不太可能没有正确实现他们的所有类,所以我不会担心。 It is more likely that they just didn't take into account the deprecation until now.更有可能的是,他们直到现在才考虑弃用。

You can disable that particular warning globally with -Wno-deprecated-copy if that is ok for you or maybe you can disable it locally with a diagnostic pragma around the Eigen header include (not sure whether it will apply to template instantiations), see eg this question for GCC.如果这对您没问题,您可以使用-Wno-deprecated-copy全局禁用该特定警告,或者您可以使用围绕 Eigen 标头包含的诊断编译指示在本地禁用它(不确定它是否适用于模板实例化),参见例如海湾合作委员会的这个问题

If you are bothered by the warnings, I would have suggested to open a bug report with Eigen about it, but they seem to already be aware of it and have recently fixed it on their git master branch, see this gitlab issue .如果您对这些警告感到困扰,我会建议与 Eigen 一起打开一个关于它的错误报告,但他们似乎已经意识到这一点,并且最近在他们的 git master 分支上修复了它,请参阅这个 gitlab 问题

So I guess if you are bothered by the warnings and don't want to disable them, you should upgrade Eigen to the current version on git master or wait for a release that includes the fix.所以我想如果您对警告感到困扰并且不想禁用它们,您应该将 Eigen 升级到 git master 上的当前版本或等待包含修复程序的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM