Clang diagnoses the inconsistent noexcept-specifier on the friend declaration of __get. Add it, and also on __get_storage.
PR libstdc++/90397 * include/std/variant (_Variant_storage<false, Types...>::_M_storage()) (_Variant_storage<true, Types...>::_M_reset())) (_Variant_storage<true, Types...>::_M_storage())): Add noexcept. (__get_storage): Likewise. (variant): Add noexcept to friend declarations for __get and __get_storage. Tested powerpc64le-linux (and with clang), committed to trunk. Backport to gcc-9-branch to follow soon.
commit ca72894f26baa3702ba0b699564bd3e356a98dba Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri May 10 22:17:41 2019 +0100 PR libstdc++/90397 fix std::variant friend declarations Clang diagnoses the inconsistent noexcept-specifier on the friend declaration of __get. Add it, and also on __get_storage. PR libstdc++/90397 * include/std/variant (_Variant_storage<false, Types...>::_M_storage()) (_Variant_storage<true, Types...>::_M_reset())) (_Variant_storage<true, Types...>::_M_storage())): Add noexcept. (__get_storage): Likewise. (variant): Add noexcept to friend declarations for __get and __get_storage. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 8c7d7f37fe2..d539df125bf 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -402,7 +402,7 @@ namespace __variant { _M_reset(); } void* - _M_storage() const + _M_storage() const noexcept { return const_cast<void*>(static_cast<const void*>( std::addressof(_M_u))); @@ -432,11 +432,11 @@ namespace __variant _M_index(_Np) { } - void _M_reset() + void _M_reset() noexcept { _M_index = variant_npos; } void* - _M_storage() const + _M_storage() const noexcept { return const_cast<void*>(static_cast<const void*>( std::addressof(_M_u))); @@ -760,7 +760,7 @@ namespace __variant // Returns the raw storage for __v. template<typename _Variant> - void* __get_storage(_Variant&& __v) + void* __get_storage(_Variant&& __v) noexcept { return __v._M_storage(); } template <typename _Maybe_variant_cookie, typename _Variant> @@ -1556,10 +1556,12 @@ namespace __variant #endif template<size_t _Np, typename _Vp> - friend constexpr decltype(auto) __detail::__variant::__get(_Vp&& __v); + friend constexpr decltype(auto) + __detail::__variant::__get(_Vp&& __v) noexcept; template<typename _Vp> - friend void* __detail::__variant::__get_storage(_Vp&& __v); + friend void* + __detail::__variant::__get_storage(_Vp&& __v) noexcept; #define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP) \ template<typename... _Tp> \