Re: [eigen] Eigen::Ref and GCC's -Wzero-as-null-pointer-constant

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hello,

Thank you for the advice. I checked what happens when using -isystem, and indeed it suppresses all warnings that come from inside Eigen. However, I am still left with this one (Same code as in my first email, full warning at the end of this email):

test_eigen.cpp:13:23: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
   fill_with_ones(myvec);

It seems that GCC considers that constructing an Eigen::Ref from a VectorXd results in an explicit zero pointer. I checked, and this also happens when directly constructing the Ref, i.e.
  Eigen::VectorXd myvec(7);
  myvec.setOnes();
  Eigen::Ref<Eigen::VectorXd> myref(myvec);
Triggers a warning. Using a fixed-size type (Such as Vector3d) also triggers the warning.

Any idea how to fix this issue in my code ? I am not sure why Eigen::Ref is misinterpreted in that way by GCC.

I agree that in general, suppressing this warning inside Eigen while keeping C++03 compliance will be difficult: as this warning is rarely turned on I am not sure it is worth the effort spent fixing it (and possibly the resulting ugliness).

Cheers,
Hervé


---------------
test_eigen.cpp: In constructor ‘Eigen::Ref<PlainObjectType, Options, StrideType>::Ref(Eigen::PlainObjectBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<_PlainObjectType, _Options, _StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*) [with Derived = Eigen::Matrix<double, 3, 1>; PlainObjectType = Eigen::Matrix<double, 3, 1>; int Options = 0; StrideType = Eigen::InnerStride<1>; typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<_PlainObjectType, _Options, _StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type = Eigen::Matrix<double, 3, 1>]’: test_eigen.cpp:13:42: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
   Eigen::Ref<Eigen::Vector3d> myref(myvec);
^



On 2016年03月05日 01:17, Christoph Hertzberg wrote:
On 2016-03-04 09:00, Marc Glisse wrote:

NULL should not be used in C++. In C++11, there is nullptr, but Eigen

still supports C++03. In the warnings you mention, some code could be

changed (ptr == 0 --> !ptr), but some would be much uglier (initializing

something to 0, returning 0).



We could define a macro EIGEN_NULLPTR to be nullptr or 0, depending on
the used standard and use that everywhere. I'm not aware of any C++03
compatible way to suppress this warning. E.g., the following definition
of a C++03-nullptr would generate the warning itself:

https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/nullptr#Solution_and_Sample_Code





The usual trick when you want to see warnings in your code but not in a

library you are using is to specify the path to that library with

-isystem instead of -I. This inhibits most warnings for files in that path.



Yes, that's the common workaround -- or we could disable this warning
inside Eigen. But we generally try to generate no warnings inside Eigen
(at least for somewhat reasonable warnings).





Christoph














Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/