简体   繁体   中英

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

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.

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. 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.

It is also a violation of the rule of 0/3/5 not to do so. 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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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