1

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?

chtz
  • 17,329
  • 4
  • 26
  • 56
LIU Qingyuan
  • 524
  • 5
  • 18

1 Answers1

7

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

walnut
  • 21,629
  • 4
  • 23
  • 59
  • Thanks, but AFAIK Eigen has no plan or timetable to support C++0x, simply ignore it seems ok for me. – LIU Qingyuan Jan 03 '20 at 05:26
  • 1
    @LIUQingyuan Why do you think Eigen doesn't support C++11? – walnut Jan 03 '20 at 06:09
  • I double checked and realized it is not the case, but IDK why I have such an impression... maybe the documentations need updates. – LIU Qingyuan Jan 03 '20 at 06:14
  • This indeed seems not to be fixed yet. I'll have to look deeper into why this case is not covered by the previous fix ... – chtz Jan 03 '20 at 10:51
  • Ok, it actually is fixed with Eigen master. I first tried this [on godbolt](https://godbolt.org/z/ZvIHrq), but they seem to still fetch from the bitbucket repository (which is not updated anymore). – chtz Jan 03 '20 at 18:48
  • @chtz Ah ok, then I will edit my answer. I didn't actually test myself. Instead I went by your last comment in the linked issue and the fact that it hadn't been closed yet. – walnut Jan 03 '20 at 18:50
  • @walnut It is not fixed for the Tensor module yet, that's why it has not been closed yet. Also on the 3.3 branch it will probably not be fixed anymore (but we may simply mask the warning). – chtz Jan 03 '20 at 18:58