From: Jonathan Wakely Date: Mon, 24 Aug 2020 15:10:07 +0000 (+0100) Subject: libstdc++: Make variant_npos conversions explicit [PR 96766] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=074436cf8cdd2a9ce75cadd36deb8301f00e55b9;p=gcc.git 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. --- diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index eb3d6779205..dd8847cf829 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -385,12 +385,16 @@ namespace __variant template struct _Variant_storage { - constexpr _Variant_storage() : _M_index(variant_npos) { } + constexpr + _Variant_storage() + : _M_index(static_cast<__index_type>(variant_npos)) + { } template - 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 struct _Variant_storage { - constexpr _Variant_storage() : _M_index(variant_npos) { } + constexpr + _Variant_storage() + : _M_index(static_cast<__index_type>(variant_npos)) + { } template - 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;