From 7d10c787386c8b789d219392028ad38d36d5f82a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 19 Feb 2019 10:31:56 +0100 Subject: [PATCH] bug #1046: add unit tests for correct propagation of alignment through std::alignment_of --- test/dense_storage.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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 +void dense_storage_alignment() +{ + #if EIGEN_HAS_ALIGNAS + + struct alignas(Alignment) Empty1 {}; + VERIFY_IS_EQUAL(std::alignment_of::value, Alignment); + + struct EIGEN_ALIGN_TO_BOUNDARY(Alignment) Empty2 {}; + VERIFY_IS_EQUAL(std::alignment_of::value, Alignment); + + struct Nested1 { EIGEN_ALIGN_TO_BOUNDARY(Alignment) T data[Size]; }; + VERIFY_IS_EQUAL(std::alignment_of::value, Alignment); + + VERIFY_IS_EQUAL( (std::alignment_of >::value), Alignment); + + const std::size_t default_alignment = internal::compute_default_alignment::value; + + VERIFY_IS_EQUAL( (std::alignment_of >::value), default_alignment); + VERIFY_IS_EQUAL( (std::alignment_of >::value), default_alignment); + struct Nested2 { Matrix mat; }; + VERIFY_IS_EQUAL(std::alignment_of::value, default_alignment); + + #endif +} + EIGEN_DECLARE_TEST(dense_storage) { dense_storage_copy(); @@ -72,5 +98,10 @@ EIGEN_DECLARE_TEST(dense_storage) dense_storage_assignment(); dense_storage_assignment(); dense_storage_assignment(); - dense_storage_assignment(); + dense_storage_assignment(); + + dense_storage_alignment(); + dense_storage_alignment(); + dense_storage_alignment(); + dense_storage_alignment(); }