CommaInitializer wrongfully asserted for 0-sized blocks

commainitialier unit-test never actually called `test_block_recursion`, which also was not correctly implemented and would have caused too deep template recursion.
This commit is contained in:
Christoph Hertzberg 2020-04-13 16:41:20 +02:00
parent c854e189e6
commit d46d726e9d
2 changed files with 18 additions and 10 deletions

View File

@ -43,7 +43,7 @@ struct CommaInitializer
inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other) inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
: m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
{ {
eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0 eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols()
&& "Cannot comma-initialize a 0x0 matrix (operator<<)"); && "Cannot comma-initialize a 0x0 matrix (operator<<)");
m_xpr.block(0, 0, other.rows(), other.cols()) = other; m_xpr.block(0, 0, other.rows(), other.cols()) = other;
} }

View File

@ -33,10 +33,16 @@ void test_blocks()
} }
if(N1 > 0) if(N1 > 0)
{
if(M1 > 0)
{ {
VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22)); VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22));
}
if(M2 > 0)
{
VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22)); VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22));
} }
}
else else
{ {
// allow insertion of zero-column blocks: // allow insertion of zero-column blocks:
@ -49,20 +55,22 @@ void test_blocks()
} }
template<int N> template<int depth, int N=0>
struct test_block_recursion struct test_block_recursion
{ {
static void run() static void run()
{ {
test_blocks<(N>>6)&3, (N>>4)&3, (N>>2)&3, N & 3>(); test_block_recursion<depth-1, N>::run();
test_block_recursion<N-1>::run(); test_block_recursion<depth-1, N + (1 << (depth-1))>::run();
} }
}; };
template<> template<int N>
struct test_block_recursion<-1> struct test_block_recursion<0,N>
{ {
static void run() { } static void run() {
test_blocks<(N>>6)&3, (N>>4)&3, (N>>2)&3, N & 3>();
}
}; };
EIGEN_DECLARE_TEST(commainitializer) EIGEN_DECLARE_TEST(commainitializer)
@ -102,5 +110,5 @@ EIGEN_DECLARE_TEST(commainitializer)
// recursively test all block-sizes from 0 to 3: // recursively test all block-sizes from 0 to 3:
test_block_recursion<(1<<8) - 1>(); test_block_recursion<8>::run();
} }