aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-03-09 10:11:13 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-03-09 10:11:13 +0100
commitf7d17689a5e4609418c55ec47d7e5924e2785460 (patch)
tree81b561d10215c6f25001b19723e5b214d9b6abbb
parentf6be7289d703ea608db01bfae1fb41cb93465363 (diff)
Add static assertion for fixed sizes Ref<>
-rw-r--r--Eigen/src/Core/Ref.h2
-rw-r--r--test/ref.cpp14
2 files changed, 15 insertions, 1 deletions
diff --git a/Eigen/src/Core/Ref.h b/Eigen/src/Core/Ref.h
index abb1e5121..ac9502bc4 100644
--- a/Eigen/src/Core/Ref.h
+++ b/Eigen/src/Core/Ref.h
@@ -95,6 +95,8 @@ protected:
template<typename Expression>
EIGEN_DEVICE_FUNC void construct(Expression& expr)
{
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(PlainObjectType,Expression);
+
if(PlainObjectType::RowsAtCompileTime==1)
{
eigen_assert(expr.rows()==1 || expr.cols()==1);
diff --git a/test/ref.cpp b/test/ref.cpp
index 769db0414..9dd2c0449 100644
--- a/test/ref.cpp
+++ b/test/ref.cpp
@@ -13,7 +13,7 @@
#endif
#define TEST_ENABLE_TEMPORARY_TRACKING
-
+#define TEST_CHECK_STATIC_ASSERTIONS
#include "main.h"
// test Ref.h
@@ -255,6 +255,17 @@ void test_ref_overloads()
test_ref_ambiguous(A, B);
}
+void test_ref_fixed_size_assert()
+{
+ Vector4f v4;
+ VectorXf vx(10);
+ VERIFY_RAISES_STATIC_ASSERT( Ref<Vector3f> y = v4; (void)y; );
+ VERIFY_RAISES_STATIC_ASSERT( Ref<Vector3f> y = vx.head<4>(); (void)y; );
+ VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = v4; (void)y; );
+ VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = vx.head<4>(); (void)y; );
+ VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = 2*v4; (void)y; );
+}
+
void test_ref()
{
for(int i = 0; i < g_repeat; i++) {
@@ -277,4 +288,5 @@ void test_ref()
}
CALL_SUBTEST_7( test_ref_overloads() );
+ CALL_SUBTEST_7( test_ref_fixed_size_assert() );
}