Commit 4273a65c authored by Tianjiao Yin's avatar Tianjiao Yin Committed by Facebook Github Bot

fix InlineFunctionRefTest by eliminating padding

Summary: std::memcmp is only meaningful for trivially-copyable objects with no padding. Before this diff, `func` is empty class and the check can fail since padding byte is undetermined.

Reviewed By: yfeldblum

Differential Revision: D19460552

fbshipit-source-id: 1b98876a12053c1e7d342e4d8a5fcb25d94f77f3
parent c05ce04c
...@@ -38,15 +38,16 @@ class InlineFunctionRefTest : public ::testing::Test { ...@@ -38,15 +38,16 @@ class InlineFunctionRefTest : public ::testing::Test {
TEST_F(InlineFunctionRefTest, BasicInvoke) { TEST_F(InlineFunctionRefTest, BasicInvoke) {
{ {
auto func = [](auto integer) { return integer; }; auto func = [dummy = int{0}](auto integer) { return integer + dummy; };
auto copy = func; auto copy = func;
auto fref = InlineFunctionRef<int(int), 24>{std::move(func)}; auto fref =
InlineFunctionRef<int(int), 2 * sizeof(uintptr_t)>{std::move(func)};
EXPECT_EQ(fref(1), 1); EXPECT_EQ(fref(1), 1);
EXPECT_EQ(fref(2), 2); EXPECT_EQ(fref(2), 2);
EXPECT_EQ(fref(3), 3); EXPECT_EQ(fref(3), 3);
EXPECT_EQ(sizeof(copy), 1); static_assert(sizeof(copy) == sizeof(int), "Make sure no padding");
EXPECT_EQ(std::memcmp(&storage(fref), &copy, 1), 0); EXPECT_EQ(std::memcmp(&storage(fref), &copy, sizeof(copy)), 0);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment