libstdc++: Make variant_npos conversions explicit [PR 96766]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Aug 2020 15:10:07 +0000 (16:10 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 24 Aug 2020 15:10:07 +0000 (16:10 +0100)
libstdc++-v3/ChangeLog:

PR libstdc++/96766
* include/std/variant (_Variant_storage): Replace implicit
conversions from size_t to __index_type with explicit casts.

libstdc++-v3/include/std/variant

index eb3d677920505d5470eb6ccbe5d6b764fdd97c3b..dd8847cf82923b0e8c2d58899f7e314d861b9140 100644 (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;