问题
I have the following code:
#include <Eigen/Dense>
struct States
{
// Eigen::VectorXd v;
Eigen::VectorXd v{Eigen::VectorXd::Ones(2)};
States() {
// v.resize(2);
// v << 1, 1;
}
};
States st;
int main() {}
Whenever I build the project under Solaris 11 (with g++4.9), with no optimizations, I get a segfault (core dumped) when running. After some digging and step-by-step debugging I think the faulty line is in
DenseCoeffBase.h
, inside function copyPacket
, namely the line 537
derived().template writePacket<StoreMode>(index,
other.derived().template packet<LoadMode>(index));
Command line I used to compile/run: g++ -std=c++11 -I ./eigen_3.2.2 example.cpp; ./a.out
Some remarks:
- If I move the declaration
States st;
insidemain()
, it works, no segfault. - If I uncomment the declaration of
v
inStates
and comment the C++11-style initialization, then usev.resize(2); v << 1, 1;
inside the constructor, it works - If I use
-O2
or-O3
optimizations, it works. - On all other platforms I tested (Ubuntu 14.04, Debian7, OS X 10.10) it works, no matter the optimization level
- The problem seems to appear only on Solaris, with no optimizations, under g++4.9
The questions I have are the following:
Is the code I wrote correct? Namely, can I safely use
C++11
-style in-class initialization, or should I just declare the vector then resize it in the constructor?If my code is correct, did anyone bumped into this issue? (I know it is highly highly unlikely but I still ask :) )
PS: I use Eigen 3.2.2 (although the issue appears on 3.2.1 also)
I would appreciate if anyone can tell me if can build/run the program on Solaris11 (no matter the compiler)
来源:https://stackoverflow.com/questions/27022190/eigen-segfault-no-optimizations-solaris