diff --git a/include/ylt/struct_pack/alignment.hpp b/include/ylt/struct_pack/alignment.hpp index df0c801b3..432cdfcb9 100644 --- a/include/ylt/struct_pack/alignment.hpp +++ b/include/ylt/struct_pack/alignment.hpp @@ -160,7 +160,7 @@ constexpr auto calculate_padding_size() { std::array + 1> padding_size{}; std::size_t offset = 0; for_each(offset, padding_size); - if (offset % align::alignment_v) { + if (align::alignment_v < T >> 0 && offset % align::alignment_v) { padding_size[struct_pack::members_count] = align::alignment_v - offset % align::alignment_v; } diff --git a/src/struct_pack/tests/test_compatible.cpp b/src/struct_pack/tests/test_compatible.cpp index 59ae1abe9..d9758b671 100644 --- a/src/struct_pack/tests/test_compatible.cpp +++ b/src/struct_pack/tests/test_compatible.cpp @@ -3,6 +3,7 @@ #include "doctest.h" #include "test_struct.hpp" +#include "ylt/struct_pack/compatible.hpp" #include "ylt/struct_pack/endian_wrapper.hpp" using namespace struct_pack; @@ -1307,4 +1308,15 @@ TEST_CASE("test nested trival_serialzable_obj_with_compatible") { CHECK(result.has_value()); CHECK(test_equal(result.value(), a_v1)); } -} \ No newline at end of file +} + +struct only_compatible { + struct_pack::compatible hi; +}; +TEST_CASE("test only_compatible") { + only_compatible o{0}; + auto buffer = struct_pack::serialize(o); + auto result = struct_pack::deserialize(buffer); + CHECK(result.has_value()); + CHECK(result->hi == o.hi); +}