Runtime error with comma initialiser and complex types
Summary
When using the comma initialiser for a vector of complex custom scalar types, the initialisation ignores any types that require promotion - resulting in a runtime error for insufficient values passed.
The same error does not occur when assigning values, only for the comma initialiser
Minimal Example
#include <Eigen/Dense>
template <typename T>
struct fvar {
std::decay_t<T> val_;
std::decay_t<T> d_;
fvar() : val_(0.0), d_(0.0) {}
template <typename V>
fvar(const V& v) : val_(v), d_(0) {}
};
int main() {
Eigen::Matrix<std::complex<fvar<double>>, -1, 1> vec_fvar(2);
// Runtime error:
vec_fvar << std::complex<fvar<double>>(1.0), 2.0;
// No runtime error:
//vec_fvar(0) = std::complex<ffd>(1.0);
//vec_fvar(1) = 2.0;
}
See godbolt reprex here: https://godbolt.org/z/1qdq5Pn6a