Clang fails to compile std::vector<Incomplete> because the static member __use_relocate cannot be evaluated for an incomplete type. Replace with a static member function that will not be odr-used until needed, by which point the type must be complete.
PR libstdc++/88840 * include/bits/stl_vector.h (vector::__use_relocate): Replace static data member with static member function _S_use_relocate(). * include/bits/vector.tcc (vector::reserve, vector::_M_realloc_insert) (vector::_M_default_append): Use _S_use_relocate() instead of __use_relocate. Tested powerpc64le-linux, committed to trunk.
commit 423d29c6e0a9e6b17901f1b04ac31060aa91c17a Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Jan 24 14:58:36 2019 +0000 PR libstdc++/88840 delay evaluation of constant until type is complete Clang fails to compile std::vector<Incomplete> because the static member __use_relocate cannot be evaluated for an incomplete type. Replace with a static member function that will not be odr-used until needed, by which point the type must be complete. PR libstdc++/88840 * include/bits/stl_vector.h (vector::__use_relocate): Replace static data member with static member function _S_use_relocate(). * include/bits/vector.tcc (vector::reserve, vector::_M_realloc_insert) (vector::_M_default_append): Use _S_use_relocate() instead of __use_relocate. diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 54de0e09ce7..43debda54f1 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -424,11 +424,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER private: #if __cplusplus >= 201103L - static constexpr bool __use_relocate = - noexcept(std::__relocate_a(std::declval<pointer>(), - std::declval<pointer>(), - std::declval<pointer>(), - std::declval<_Tp_alloc_type&>())); + static constexpr bool + _S_use_relocate() + { + return noexcept(std::__relocate_a(std::declval<pointer>(), + std::declval<pointer>(), + std::declval<pointer>(), + std::declval<_Tp_alloc_type&>())); + } #endif protected: diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index edd0b6aeaa8..4cf0e809fe9 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -73,7 +73,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER const size_type __old_size = size(); pointer __tmp; #if __cplusplus >= 201103L - if constexpr (__use_relocate) + if constexpr (_S_use_relocate()) { __tmp = this->_M_allocate(__n); std::__relocate_a(this->_M_impl._M_start, @@ -457,7 +457,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER __new_finish = pointer(); #if __cplusplus >= 201103L - if constexpr (__use_relocate) + if constexpr (_S_use_relocate()) { __new_finish = std::__relocate_a @@ -498,7 +498,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER __throw_exception_again; } #if __cplusplus >= 201103L - if constexpr (!__use_relocate) + if constexpr (!_S_use_relocate()) #endif std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator()); _GLIBCXX_ASAN_ANNOTATE_REINIT; @@ -639,7 +639,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_check_len(__n, "vector::_M_default_append"); pointer __new_start(this->_M_allocate(__len)); #if __cplusplus >= 201103L - if constexpr (__use_relocate) + if constexpr (_S_use_relocate()) { __try {