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

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


On Fri, 4 Mar 2016, Hervé Audren wrote:

I am a quite long-time user of Eigen, but I encountered a weird problem today. I was converting an old code that used ints to a newer API taking std::string (So, C++11). Unfortunately, the literal 0 can be promoted to char*, and thus to std::string, triggering an error, namely "basic_string::_S_construct null not valid". I noticed that GCC has zero-as-null-pointer-constant warning designed to catch such programming errors. Unfortunately, as I turned it on, I noticed that methods taking an Eigen::Ref as an argument triggered the warning (Code sample below):
warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
  Eigen::VectorXd myvec;
  my_method(myvec);

I think that somewhere in RefBase/MapBase/Memory a literal zero is used instead of NULL (Which is correctly not flagged by GCC). But maybe it is GCC incorrectly reporting the warning ?

I would really like to be able to enable that flag in my codebase to track down places where I forgot to change the ints to strings.

Hello,

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

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.

As a temporary hack, you could also edit the file bits/basic_string.h in gcc's headers to add a constructor basic_string(nullptr_t) = delete; so most issues would appear at compile-time.

--
Marc Glisse



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