[eigen] Eigen::Ref and GCC's -Wzero-as-null-pointer-constant |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Eigen::Ref and GCC's -Wzero-as-null-pointer-constant
- From: Hervé Audren <h.audren@xxxxxxxxxx>
- Date: Fri, 4 Mar 2016 14:01:01 +0900
- Authentication-results: lists.tuxfamily.org; dkim=none (message not signed) header.d=none;lists.tuxfamily.org; dmarc=none action=none header.from=aist.go.jp;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aist.go.jp; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=NAW7PYfCsmS6S2/O7Fa58wFndXg7cZp/OBP2csHhu9k=; b=Y8smDS+mY5JSHks/BFv1kx0dHCwCneAfkeaIgwaDrWwp8p44LUp4KG0TSHjOrtJ993ag94UNwFRmnoaA0IvZcF6rxQKID0X6mwpCJiHdqt07PDssY25ZiMHAp6YZg8fplfnVDM/PGc/EnN5/qHtuWZYuIxK8cxZHF0nN8f1E1mk=
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
Hello everyone,
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.
Thanks,
Hervé
---- Contents ----
Minimal code example:
#include <Eigen/Core>
void fill_with_ones(Eigen::Ref<Eigen::VectorXd> vec)
{
vec.setOnes();
}
int main()
{
Eigen::VectorXd myvec(7);
fill_with_ones(myvec);
return 0;
}
Compiled with (Ubuntu 14.04, gcc4.8.4 - Same behaviour on Arch with gcc
5.3.0):
g++ -std=c++11 -o test_eigen -I/usr/include/eigen3 test_eigen.cpp
Full Warning Log:
In file included from /usr/include/eigen3/Eigen/Core:256:0,
from test_eigen.cpp:1:
/usr/include/eigen3/Eigen/src/Core/util/Memory.h: In function ‘void*
Eigen::internal::handmade_aligned_malloc(std::size_t)’:
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:107:19: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (original == 0) return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:107:29: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (original == 0) return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h: In function ‘void*
Eigen::internal::handmade_aligned_realloc(void*, std::size_t, std::size_t)’:
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:126:14: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (ptr == 0) return handmade_aligned_malloc(size);
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:130:19: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (original == 0) return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:130:29: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (original == 0) return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h: In function ‘void*
Eigen::internal::generic_aligned_realloc(void*, std::size_t, std::size_t)’:
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:154:12: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (ptr==0)
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:160:12: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:164:17: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (newptr == 0)
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:169:12: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
return 0;
^
/usr/include/eigen3/Eigen/src/Core/util/Memory.h:172:14: warning: zero
as null pointer constant [-Wzero-as-null-pointer-constant]
if (ptr != 0)
^
In file included from /usr/include/eigen3/Eigen/Core:326:0,
from test_eigen.cpp:1:
/usr/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h:
At global scope:
/usr/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h:28:91:
warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0,
std::ptrdiff_t* l2=0)
^
/usr/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h:28:91:
warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
/usr/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h:28:91:
warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
/usr/include/eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h:28:91:
warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
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, -1, 1>; PlainObjectType =
Eigen::Matrix<double, -1, 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, -1, 1>]’:
test_eigen.cpp:11:23: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
fill_with_ones(myvec);
^
test_eigen.cpp:11:23: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
In file included from /usr/include/eigen3/Eigen/Core:308:0,
from test_eigen.cpp:1:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of
‘Eigen::RefBase<Derived>::RefBase() [with Derived =
Eigen::Ref<Eigen::Matrix<double, -1, 1> >]’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:196:5: required from
‘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, -1, 1>; PlainObjectType =
Eigen::Matrix<double, -1, 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, -1, 1>]’
test_eigen.cpp:11:23: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:150:100: warning: zero as null
pointer constant [-Wzero-as-null-pointer-constant]
StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
^