Fix the copy constructor in Replaceable
[folly.git] / folly / test / ReplaceableTest.cpp
index 00eb01d9867ba38fa45de2d3bfeaf90ba853436d..6ab885095bcd1ebf8b6ca26836375d52d83b7381 100644 (file)
@@ -22,6 +22,7 @@ using namespace ::testing;
 using namespace ::folly;
 
 namespace {
+struct Basic {};
 struct alignas(128) BigAlign {};
 struct HasConst final {
   bool const b1;
@@ -81,6 +82,7 @@ using StaticAttributeTypes = ::testing::Types<
     float,
     double,
     char[11],
+    Basic,
     BigAlign,
     HasConst,
     HasRef,
@@ -250,6 +252,18 @@ TEST(ReplaceableTest, Basics) {
   EXPECT_TRUE(rHasConstB->b1);
 }
 
+TEST(ReplaceableTest, Constructors) {
+  Basic b{};
+  // From existing `T`
+  auto rBasicCopy1 = Replaceable<Basic>(b);
+  auto rBasicMove1 = Replaceable<Basic>(std::move(b));
+  // From existing `Replaceable<T>`
+  auto rBasicCopy2 = Replaceable<Basic>(rBasicCopy1);
+  auto rBasicMove2 = Replaceable<Basic>(std::move(rBasicMove1));
+  (void)rBasicCopy2;
+  (void)rBasicMove2;
+}
+
 TEST(ReplaceableTest, DestructsWhenExpected) {
   int i{0};
   {