'Eigen assert in a function called from variadic template function

I have a small lib based on Eigen 3.3.9 with all the interesting parts here in Godbolt. The problem is it crashes (Godbolt reports return code 139 instead of 0), and I don't know why. The crash happens here in Eigen, because rows() and cols() calls refer to null pointer in nested objects. Here, row = 0, col = 0, this = @0x7fffffffdf60 Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 1> ... although not a single member appears.

    EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE Scalar&
    operator()(Index row, Index col)
    {
      eigen_assert(row >= 0 && row < rows()
          && col >= 0 && col < cols());
      return coeffRef(row, col);
    }

which gets called directly from here:

Eigen::MatrixXd PolynomApprox::doCalculateVandermonde(uint32_t const aVariableIndex, uint32_t const aSampleCount, double const * const aSamplesX, uint32_t const aDegree) {
  Eigen::MatrixXd result(aSampleCount, aDegree + 1u);

  for(uint32_t i = 0u; i < aSampleCount; ++i) {
    for(uint32_t j = 0u; j <= aDegree; ++j) {
       result(i, j) = ::pow(normalize(aSamplesX[i], aVariableIndex), j);
    }
  }
  return result;
}

This used to work in the previous version without variadic template function. Why does this happen? Thanks in advance: Balázs Bámer



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source