AutoDiffScalar mixed-type min/max doesn't work with expressions
Submitted by Daniel Vollmer
Assigned to Nobody
Link to original bugzilla bug (#1223)
Version: 3.3 (current stable)
Description
The following example fails to compile as soon as the argument to min/max is an expression, because the return-type of ADS<DerType&> of min/max is being initialized with only the scalar value, not setting up the m_derivatives reference, I think.
This is similar-isa to bug #1222 (closed).
#include <algorithm>
#include "Eigen/Core"
#include "unsupported/Eigen/AutoDiff"
int main (int argc, char const *argv[])
{
using std::min;
typedef Eigen::AutoDiffScalarEigen::Vector3d AD;
const double _cv1_3 = 1.0;
const AD chi_3 = 1.0;
const AD denom = 1.0;
// fails because implementation of min attempts to construct ADS<DerType&> via constructor AutoDiffScalar(const Real& value) without initializing m_derivatives (which is a reference in this case)
const AD t = min(denom / chi_3, 1.0);
// const AD t2 = min(denom / (chi_3 * _cv1_3), 1.0);
return 0;
}