libstdc++: Make variant_npos conversions explicit [PR 96766]

libstdc++-v3/ChangeLog:

	PR libstdc++/96766
	* include/std/variant (_Variant_storage): Replace implicit
	conversions from size_t to __index_type with explicit casts.
This commit is contained in:
Jonathan Wakely 2020-08-24 16:10:07 +01:00
parent ac4e9090fc
commit 074436cf8c

View File

@ -385,12 +385,16 @@ namespace __variant
template<typename... _Types>
struct _Variant_storage<false, _Types...>
{
constexpr _Variant_storage() : _M_index(variant_npos) { }
constexpr
_Variant_storage()
: _M_index(static_cast<__index_type>(variant_npos))
{ }
template<size_t _Np, typename... _Args>
constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
constexpr
_Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
: _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...),
_M_index(_Np)
_M_index{_Np}
{ }
void _M_reset()
@ -403,7 +407,7 @@ namespace __variant
std::_Destroy(std::__addressof(__this_mem));
}, __variant_cast<_Types...>(*this));
_M_index = variant_npos;
_M_index = static_cast<__index_type>(variant_npos);
}
~_Variant_storage()
@ -432,16 +436,20 @@ namespace __variant
template<typename... _Types>
struct _Variant_storage<true, _Types...>
{
constexpr _Variant_storage() : _M_index(variant_npos) { }
constexpr
_Variant_storage()
: _M_index(static_cast<__index_type>(variant_npos))
{ }
template<size_t _Np, typename... _Args>
constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
constexpr
_Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
: _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...),
_M_index(_Np)
_M_index{_Np}
{ }
void _M_reset() noexcept
{ _M_index = variant_npos; }
{ _M_index = static_cast<__index_type>(variant_npos); }
void*
_M_storage() const noexcept
@ -455,7 +463,7 @@ namespace __variant
{
if constexpr (__variant::__never_valueless<_Types...>())
return true;
return this->_M_index != __index_type(variant_npos);
return this->_M_index != static_cast<__index_type>(variant_npos);
}
_Variadic_union<_Types...> _M_u;