aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2019-02-19 10:31:56 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2019-02-19 10:31:56 +0100
commit7d10c787386c8b789d219392028ad38d36d5f82a (patch)
tree64173fc8e9b89cc388e5e0f917ec731ede6634f9
parent7580112c3168e6e436204ac4e584a86c3ab53498 (diff)
bug #1046: add unit tests for correct propagation of alignment through std::alignment_of
-rw-r--r--test/dense_storage.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/test/dense_storage.cpp b/test/dense_storage.cpp
index 1150ec52b..7fa25859d 100644
--- a/test/dense_storage.cpp
+++ b/test/dense_storage.cpp
@@ -52,6 +52,32 @@ void dense_storage_assignment()
VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
}
+template<typename T, int Size, std::size_t Alignment>
+void dense_storage_alignment()
+{
+ #if EIGEN_HAS_ALIGNAS
+
+ struct alignas(Alignment) Empty1 {};
+ VERIFY_IS_EQUAL(std::alignment_of<Empty1>::value, Alignment);
+
+ struct EIGEN_ALIGN_TO_BOUNDARY(Alignment) Empty2 {};
+ VERIFY_IS_EQUAL(std::alignment_of<Empty2>::value, Alignment);
+
+ struct Nested1 { EIGEN_ALIGN_TO_BOUNDARY(Alignment) T data[Size]; };
+ VERIFY_IS_EQUAL(std::alignment_of<Nested1>::value, Alignment);
+
+ VERIFY_IS_EQUAL( (std::alignment_of<internal::plain_array<T,Size,AutoAlign,Alignment> >::value), Alignment);
+
+ const std::size_t default_alignment = internal::compute_default_alignment<T,Size>::value;
+
+ VERIFY_IS_EQUAL( (std::alignment_of<DenseStorage<T,Size,1,1,AutoAlign> >::value), default_alignment);
+ VERIFY_IS_EQUAL( (std::alignment_of<Matrix<T,Size,1,AutoAlign> >::value), default_alignment);
+ struct Nested2 { Matrix<T,Size,1,AutoAlign> mat; };
+ VERIFY_IS_EQUAL(std::alignment_of<Nested2>::value, default_alignment);
+
+ #endif
+}
+
EIGEN_DECLARE_TEST(dense_storage)
{
dense_storage_copy<int,Dynamic,Dynamic>();
@@ -72,5 +98,10 @@ EIGEN_DECLARE_TEST(dense_storage)
dense_storage_assignment<float,Dynamic,Dynamic>();
dense_storage_assignment<float,Dynamic,3>();
dense_storage_assignment<float,4,Dynamic>();
- dense_storage_assignment<float,4,3>();
+ dense_storage_assignment<float,4,3>();
+
+ dense_storage_alignment<float,16,8>();
+ dense_storage_alignment<float,16,16>();
+ dense_storage_alignment<float,16,32>();
+ dense_storage_alignment<float,16,64>();
}