As the PR points out, we aren't qualifying calls to __ref_cast, and have 'constexpr' on function templates that can never be usable in constant expressions.
This fixes it, and also simplifies __variant::__erased_dtor by using std::_Destroy, although that requires including quite a lot more code, for iterator_traits and allocator_traits. If that matters (probably not) then <bits/stl_construct.h> could be split up to move _Construct and _Destroy to a new <bits/stl_construct_base.h>. Or maybe I should just leave __erased_dtor alone (apart from qualifying the __ref_cast call). Anybody feel strongly either way? PR libstdc++/80939 * include/std/variant (__erased_ctor, __erased_assign, __erased_swap) (__erased_hash): Remove constexpr specifier and qualify calls to __ref_cast. (__erased_dtor): Remove constexpr specifier and use _Destroy.
commit 8a813292bd7170eb160b509122fc3bb388b87f12 Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Jun 2 13:00:52 2017 +0100 PR libstdc++/80939 Remove unmeetable constexpr specifiers PR libstdc++/80939 * include/std/variant (__erased_ctor, __erased_assign, __erased_swap) (__erased_hash): Remove constexpr specifier and qualify calls to __ref_cast. (__erased_dtor): Remove constexpr specifier and use _Destroy. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index b9824a5..e5fe9f9 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -44,6 +44,9 @@ #include <bits/invoke.h> #include <ext/aligned_buffer.h> #include <bits/parse_numbers.h> +#include <bits/stl_iterator_base_types.h> +#include <bits/stl_iterator_base_funcs.h> +#include <bits/stl_construct.h> namespace std _GLIBCXX_VISIBILITY(default) { @@ -238,30 +241,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Various functions as "vtable" entries, where those vtables are used by // polymorphic operations. template<typename _Lhs, typename _Rhs> - constexpr void + void __erased_ctor(void* __lhs, void* __rhs) - { ::new (__lhs) remove_reference_t<_Lhs>(__ref_cast<_Rhs>(__rhs)); } + { + using _Type = remove_reference_t<_Lhs>; + ::new (__lhs) _Type(__variant::__ref_cast<_Rhs>(__rhs)); + } template<typename _Variant, size_t _Np> - constexpr void + void __erased_dtor(_Variant&& __v) + { std::_Destroy(std::__addressof(__get<_Np>(__v))); } + + template<typename _Lhs, typename _Rhs> + void + __erased_assign(void* __lhs, void* __rhs) { - auto&& __element = __get<_Np>(std::forward<_Variant>(__v)); - using _Type = std::remove_reference_t<decltype(__element)>; - __element.~_Type(); + __variant::__ref_cast<_Lhs>(__lhs) = __variant::__ref_cast<_Rhs>(__rhs); } template<typename _Lhs, typename _Rhs> - constexpr void - __erased_assign(void* __lhs, void* __rhs) - { __ref_cast<_Lhs>(__lhs) = __ref_cast<_Rhs>(__rhs); } - - template<typename _Lhs, typename _Rhs> - constexpr void + void __erased_swap(void* __lhs, void* __rhs) { using std::swap; - swap(__ref_cast<_Lhs>(__lhs), __ref_cast<_Rhs>(__rhs)); + swap(__variant::__ref_cast<_Lhs>(__lhs), + __variant::__ref_cast<_Rhs>(__rhs)); } #define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \ @@ -283,11 +288,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #undef _VARIANT_RELATION_FUNCTION_TEMPLATE template<typename _Tp> - constexpr size_t + size_t __erased_hash(void* __t) { return std::hash<remove_cv_t<remove_reference_t<_Tp>>>{}( - __ref_cast<_Tp>(__t)); + __variant::__ref_cast<_Tp>(__t)); } // Defines members and ctors.