summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tag_compound.h2
-rw-r--r--include/tag_list.h4
-rw-r--r--test/nbttest.cpp2
3 files changed, 5 insertions, 3 deletions
diff --git a/include/tag_compound.h b/include/tag_compound.h
index 1f1c5f3e1a..8e09ff4834 100644
--- a/include/tag_compound.h
+++ b/include/tag_compound.h
@@ -127,7 +127,7 @@ private:
template<class T, class... Args>
std::pair<tag_compound::iterator, bool> tag_compound::emplace(const std::string& key, Args&&... args)
{
- return put(key, value(T(std::forward<Args>(args)...)));
+ return put(key, value(make_unique<T>(std::forward<Args>(args)...)));
}
}
diff --git a/include/tag_list.h b/include/tag_list.h
index 137b53d5d1..f1f5e6dec1 100644
--- a/include/tag_list.h
+++ b/include/tag_list.h
@@ -175,7 +175,7 @@ void tag_list::emplace_back(Args&&... args)
el_type_ = T::type;
else if(el_type_ != T::type)
throw std::bad_cast();
- tags.emplace_back(T(std::forward<Args>(args)...));
+ tags.emplace_back(make_unique<T>(std::forward<Args>(args)...));
}
template<class T, class Arg>
@@ -184,7 +184,7 @@ void tag_list::init(std::initializer_list<Arg> init)
el_type_ = T::type;
tags.reserve(init.size());
for(const Arg& arg: init)
- tags.emplace_back(T(arg));
+ tags.emplace_back(make_unique<T>(arg));
}
}
diff --git a/test/nbttest.cpp b/test/nbttest.cpp
index fdc6d5e3f0..7e3a78b341 100644
--- a/test/nbttest.cpp
+++ b/test/nbttest.cpp
@@ -274,6 +274,8 @@ void test_tag_list()
EXPECT_EXCEPTION(list.at(-1), std::out_of_range);
list.set(1, tag_string("baz"));
+ EXPECT_EXCEPTION(list.set(1, value(nullptr)), std::bad_cast);
+ EXPECT_EXCEPTION(list.set(1, -42), std::bad_cast);
ASSERT(static_cast<std::string>(list[1]) == "baz");
ASSERT(list.size() == 2);