From be46043e07689050ba4522e907db618d26fc1bb8 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 23 Apr 2019 10:55:28 +0100 Subject: [PATCH] Make some std::variant helper functions noexcept * include/std/variant (__detail::__variant::__ref_cast): Remove unused function. (__detail::__variant::_Uninitialized::_M_get) (__detail::__variant::__get) (__gen_vtable_impl::__element_by_index_or_cookie): Add noexcept. From-SVN: r270501 --- libstdc++-v3/ChangeLog | 8 +++++++ libstdc++-v3/include/std/variant | 36 ++++++++++++++------------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index af3372081b5..9dad28f502a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2019-04-23 Jonathan Wakely + + * include/std/variant (__detail::__variant::__ref_cast): Remove + unused function. + (__detail::__variant::_Uninitialized::_M_get) + (__detail::__variant::__get) + (__gen_vtable_impl::__element_by_index_or_cookie): Add noexcept. + 2019-04-21 Iain Sandoe * testsuite/17_intro/headers/c++1998/charset.cc: Skip for Darwin8 diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index e153363bbf3..08378eee816 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -203,16 +203,16 @@ namespace __variant : _M_storage(std::forward<_Args>(__args)...) { } - constexpr const _Type& _M_get() const & + constexpr const _Type& _M_get() const & noexcept { return _M_storage; } - constexpr _Type& _M_get() & + constexpr _Type& _M_get() & noexcept { return _M_storage; } - constexpr const _Type&& _M_get() const && + constexpr const _Type&& _M_get() const && noexcept { return std::move(_M_storage); } - constexpr _Type&& _M_get() && + constexpr _Type&& _M_get() && noexcept { return std::move(_M_storage); } _Type _M_storage; @@ -229,33 +229,29 @@ namespace __variant _Type(std::forward<_Args>(__args)...); } - const _Type& _M_get() const & + const _Type& _M_get() const & noexcept { return *_M_storage._M_ptr(); } - _Type& _M_get() & + _Type& _M_get() & noexcept { return *_M_storage._M_ptr(); } - const _Type&& _M_get() const && + const _Type&& _M_get() const && noexcept { return std::move(*_M_storage._M_ptr()); } - _Type&& _M_get() && + _Type&& _M_get() && noexcept { return std::move(*_M_storage._M_ptr()); } __gnu_cxx::__aligned_membuf<_Type> _M_storage; }; - template - _Ref __ref_cast(void* __ptr) - { - return static_cast<_Ref>(*static_cast*>(__ptr)); - } - template - constexpr decltype(auto) __get(in_place_index_t<0>, _Union&& __u) + constexpr decltype(auto) + __get(in_place_index_t<0>, _Union&& __u) noexcept { return std::forward<_Union>(__u)._M_first._M_get(); } template - constexpr decltype(auto) __get(in_place_index_t<_Np>, _Union&& __u) + constexpr decltype(auto) + __get(in_place_index_t<_Np>, _Union&& __u) noexcept { return __variant::__get(in_place_index<_Np-1>, std::forward<_Union>(__u)._M_rest); @@ -263,7 +259,8 @@ namespace __variant // Returns the typed storage for __v. template - constexpr decltype(auto) __get(_Variant&& __v) + constexpr decltype(auto) + __get(_Variant&& __v) noexcept { return __variant::__get(std::in_place_index<_Np>, std::forward<_Variant>(__v)._M_u); @@ -981,7 +978,7 @@ namespace __variant template static constexpr decltype(auto) - __element_by_index_or_cookie(_Variant&& __var) + __element_by_index_or_cookie(_Variant&& __var) noexcept { if constexpr (__index != variant_npos) return __variant::__get<__index>(std::forward<_Variant>(__var)); @@ -1166,8 +1163,7 @@ namespace __variant template constexpr add_pointer_t - get_if(const variant<_Types...>* __ptr) - noexcept + get_if(const variant<_Types...>* __ptr) noexcept { static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>, "T should occur for exactly once in alternatives"); -- 2.30.2