aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2018-11-22 19:10:05 +0100
committerMarc Glisse <glisse@gcc.gnu.org>2018-11-22 18:10:05 +0000
commitff2e7f1973807759f52808a2594e0635ced69619 (patch)
tree1e01d6887f8679c8849b7d04647aed21957b9c1b
parenteeae9314d4449b765ab41a7bfbb8938d0bc83fa9 (diff)
downloadgcc-ff2e7f1973807759f52808a2594e0635ced69619.zip
gcc-ff2e7f1973807759f52808a2594e0635ced69619.tar.gz
gcc-ff2e7f1973807759f52808a2594e0635ced69619.tar.bz2
Improve relocation
2018-11-22 Marc Glisse <marc.glisse@inria.fr> PR libstdc++/87106 * include/bits/stl_algobase.h: Include <type_traits>. (__niter_base): Add noexcept specification. * include/bits/stl_deque.h: Include <bits/stl_uninitialized.h>. (__is_trivially_relocatable): Specialize for deque. * include/bits/stl_iterator.h: Include <type_traits>. (__niter_base): Add noexcept specification. * include/bits/stl_uninitialized.h (__is_trivially_relocatable): Add parameter for meta-programming. (__relocate_a_1, __relocate_a): Add noexcept specification. * include/bits/stl_vector.h (__use_relocate): Test __relocate_a. From-SVN: r266386
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h4
-rw-r--r--libstdc++-v3/include/bits/stl_deque.h10
-rw-r--r--libstdc++-v3/include/bits/stl_iterator.h5
-rw-r--r--libstdc++-v3/include/bits/stl_uninitialized.h13
-rw-r--r--libstdc++-v3/include/bits/stl_vector.h8
6 files changed, 45 insertions, 9 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 267ec39..1e8072d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,17 @@
+2018-11-22 Marc Glisse <marc.glisse@inria.fr>
+
+ PR libstdc++/87106
+ * include/bits/stl_algobase.h: Include <type_traits>.
+ (__niter_base): Add noexcept specification.
+ * include/bits/stl_deque.h: Include <bits/stl_uninitialized.h>.
+ (__is_trivially_relocatable): Specialize for deque.
+ * include/bits/stl_iterator.h: Include <type_traits>.
+ (__niter_base): Add noexcept specification.
+ * include/bits/stl_uninitialized.h (__is_trivially_relocatable):
+ Add parameter for meta-programming.
+ (__relocate_a_1, __relocate_a): Add noexcept specification.
+ * include/bits/stl_vector.h (__use_relocate): Test __relocate_a.
+
2018-11-22 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/85930
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index b1ecd83..d1e1f67 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -69,6 +69,9 @@
#include <debug/debug.h>
#include <bits/move.h> // For std::swap
#include <bits/predefined_ops.h>
+#if __cplusplus >= 201103L
+# include <type_traits>
+#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -275,6 +278,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Iterator>
inline _Iterator
__niter_base(_Iterator __it)
+ _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
{ return __it; }
// Reverse the __niter_base transformation to get a
diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h
index 555be16..5d1b428 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -61,6 +61,7 @@
#include <bits/stl_iterator_base_funcs.h>
#if __cplusplus >= 201103L
#include <initializer_list>
+#include <bits/stl_uninitialized.h> // for __is_trivially_relocatable
#endif
#include <debug/assertions.h>
@@ -2366,6 +2367,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#undef _GLIBCXX_DEQUE_BUF_SIZE
_GLIBCXX_END_NAMESPACE_CONTAINER
+
+#if __cplusplus >= 201103L
+ // std::allocator is safe, but it is not the only allocator
+ // for which this is valid.
+ template<class _Tp>
+ struct __is_trivially_relocatable<_GLIBCXX_STD_C::deque<_Tp>>
+ : true_type { };
+#endif
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index d4a3e9e..1f0c081 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -65,6 +65,10 @@
#include <bits/move.h>
#include <bits/ptr_traits.h>
+#if __cplusplus >= 201103L
+# include <type_traits>
+#endif
+
#if __cplusplus > 201402L
# define __cpp_lib_array_constexpr 201603
#endif
@@ -1004,6 +1008,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Iterator, typename _Container>
_Iterator
__niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
+ _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
{ return __it.base(); }
#if __cplusplus >= 201103L
diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h
index 8839bfd..cec0134 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -894,14 +894,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
// This class may be specialized for specific types.
- template<typename _Tp>
+ template<typename _Tp, typename = void>
struct __is_trivially_relocatable
: is_trivial<_Tp> { };
template <typename _Tp, typename _Up>
inline __enable_if_t<std::__is_trivially_relocatable<_Tp>::value, _Tp*>
__relocate_a_1(_Tp* __first, _Tp* __last,
- _Tp* __result, allocator<_Up>& __alloc)
+ _Tp* __result, allocator<_Up>& __alloc) noexcept
{
ptrdiff_t __count = __last - __first;
if (__count > 0)
@@ -914,15 +914,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline _ForwardIterator
__relocate_a_1(_InputIterator __first, _InputIterator __last,
_ForwardIterator __result, _Allocator& __alloc)
+ noexcept(noexcept(std::__relocate_object_a(std::addressof(*__result),
+ std::addressof(*__first),
+ __alloc)))
{
typedef typename iterator_traits<_InputIterator>::value_type
_ValueType;
typedef typename iterator_traits<_ForwardIterator>::value_type
_ValueType2;
static_assert(std::is_same<_ValueType, _ValueType2>::value);
- static_assert(noexcept(std::__relocate_object_a(std::addressof(*__result),
- std::addressof(*__first),
- __alloc)));
_ForwardIterator __cur = __result;
for (; __first != __last; ++__first, (void)++__cur)
std::__relocate_object_a(std::__addressof(*__cur),
@@ -935,6 +935,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline _ForwardIterator
__relocate_a(_InputIterator __first, _InputIterator __last,
_ForwardIterator __result, _Allocator& __alloc)
+ noexcept(noexcept(__relocate_a_1(std::__niter_base(__first),
+ std::__niter_base(__last),
+ std::__niter_base(__result), __alloc)))
{
return __relocate_a_1(std::__niter_base(__first),
std::__niter_base(__last),
diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h
index 05f9b7e..07dcd58 100644
--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -425,10 +425,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
private:
#if __cplusplus >= 201103L
static constexpr bool __use_relocate =
- noexcept(std::__relocate_object_a(
- std::addressof(*std::declval<pointer>()),
- std::addressof(*std::declval<pointer>()),
- std::declval<_Tp_alloc_type&>()));
+ noexcept(std::__relocate_a(std::declval<pointer>(),
+ std::declval<pointer>(),
+ std::declval<pointer>(),
+ std::declval<_Tp_alloc_type&>()));
#endif
protected: