- status: open --> closed-out-of-date
- Group: -->
On one of my computers, I started getting segmentation faults at the program initialization (before it even enters main()), which I managed to narrow down to the following code:
#include <ql/math/distributions/normaldistribution.hpp>
#include <boost/math/distributions/students_t.hpp>
class MarginStudent {
private:
std::unique_ptr<boost::math::students_t_distribution<>> p2Dist;
boost::optional<double> inv_cdf(double const p) const;
public:
MarginStudent(unsigned const v);
};
MarginStudent::MarginStudent(unsigned const v)
: p2Dist(new boost::math::students_t_distribution<>(v))
{}
boost::optional<double> MarginStudent::inv_cdf(double const p) const
{
return quantile(*p2Dist, p);
}
int main(int argc, char *argv[]) {
return 0;
}
Note that the main() is completely empty, yet the code still crashes. Gdb reports the following when reading the core dump:
Program terminated with signal 11, Segmentation fault.
#0 0xb694f608 in boost::math::lanczos::lanczos_initializer<boost::math::lanczos::lanczos17m64, long double>::init::init() () from /usr/lib/libQuantLib.so.0
To reproduce the error, save the code as test.cpp and compile as: g++ -std=c++11 -O -lQuantLib test.cpp.
It 'works' with any optimization option (from -O to -O3).
Placing a breakpoint at the start of the offending function, I see that it being entered when compiled without optimization, but with optimization on, the seg-fault happens just before entering the function (so it never reaches the breakpoint).
System info: 32-bit Solydxk, a Linux distro based on Debian testing. It has gcc v. 4.9, boost v. 1.55 and quantlib v. 1.4-2+b1.
PS: I know it does not make sense to link quantlib when it is not used, but this is because in my code, I use it. The example above is just the minimal code that still produces the error. In a way, it makes it much weirder, as the code crashes in libQuantLib, even it is not used anywhere..