Null out the union for the Undefined type (#444)

This commit is contained in:
Rick Winter 2020-08-13 13:11:17 -07:00 committed by GitHub
parent a7f17cee5a
commit e3394ec3f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
#include <atomic>
#include <chrono>
#include <memory>
#include <new> //For the non-allocating placement new
#include <string>
#include <type_traits>
@ -39,7 +40,7 @@ namespace Azure { namespace Core {
};
public:
ContextValue() noexcept : m_contextValueType(ContextValueType::Undefined) {}
ContextValue() noexcept : m_contextValueType(ContextValueType::Undefined), m_b(false) {}
ContextValue(bool b) noexcept : m_contextValueType(ContextValueType::Bool), m_b(b) {}
ContextValue(int i) noexcept : m_contextValueType(ContextValueType::Int), m_i(i) {}
ContextValue(const std::string& s) : m_contextValueType(ContextValueType::StdString), m_s(s) {}
@ -47,12 +48,8 @@ namespace Azure { namespace Core {
: m_contextValueType(ContextValueType::UniquePtr), m_s(std::move(s))
{
}
template <
class DerivedFromValueBase,
typename std::
enable_if<std::is_convertible<DerivedFromValueBase*, ValueBase*>::value, int>::type
= 0>
ContextValue(std::unique_ptr<DerivedFromValueBase>&& p) noexcept
ContextValue(std::unique_ptr<ValueBase>&& p) noexcept
: m_contextValueType(ContextValueType::UniquePtr), m_p(std::move(p))
{
}