[cfe-commits] [libcxx] r119609 - in /libcxx/trunk: include/memory test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp
Howard Hinnant
hhinnant at apple.com
Wed Nov 17 17:40:00 PST 2010
Author: hhinnant
Date: Wed Nov 17 19:40:00 2010
New Revision: 119609
URL: http://llvm.org/viewvc/llvm-project?rev=119609&view=rev
Log:
LWG 1404
Modified:
libcxx/trunk/include/memory
libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp
libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=119609&r1=119608&r2=119609&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Nov 17 19:40:00 2010
@@ -52,8 +52,11 @@
| pointer_traits<pointer>::rebind<const void>
const_void_pointer;
typedef Alloc::difference_type
- | ptrdiff_t difference_type;
- typedef Alloc::size_type | size_t size_type;
+ | pointer_traits<pointer>::difference_type
+ difference_type;
+ typedef Alloc::size_type
+ | make_unsigned<difference_type>::type
+ size_type;
typedef Alloc::propagate_on_container_copy_assignment
| false_type propagate_on_container_copy_assignment;
typedef Alloc::propagate_on_container_move_assignment
@@ -856,7 +859,7 @@
typedef _Tp* type;
};
-}
+} // __pointer_type_imp
template <class _Tp, class _Dp>
struct __pointer_type
@@ -972,14 +975,14 @@
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
-template <class _Alloc, bool = __has_size_type<_Alloc>::value>
+template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
struct __size_type
{
- typedef size_t type;
+ typedef typename make_unsigned<_DiffType>::type type;
};
-template <class _Alloc>
-struct __size_type<_Alloc, true>
+template <class _Alloc, class _DiffType>
+struct __size_type<_Alloc, _DiffType, true>
{
typedef typename _Alloc::size_type type;
};
@@ -1292,6 +1295,18 @@
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
+template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
+struct __alloc_traits_difference_type
+{
+ typedef typename pointer_traits<_Ptr>::difference_type type;
+};
+
+template <class _Alloc, class _Ptr>
+struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
+{
+ typedef typename _Alloc::difference_type type;
+};
+
template <class _Alloc>
struct _LIBCPP_VISIBLE allocator_traits
{
@@ -1303,8 +1318,8 @@
typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
- typedef typename __pointer_traits_difference_type<allocator_type>::type difference_type;
- typedef typename __size_type<allocator_type>::type size_type;
+ typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
+ typedef typename __size_type<allocator_type, difference_type>::type size_type;
typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
propagate_on_container_copy_assignment;
Modified: libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp?rev=119609&r1=119608&r2=119609&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp Wed Nov 17 19:40:00 2010
@@ -13,7 +13,7 @@
// struct allocator_traits
// {
// typedef Alloc::difference_type
-// | ptrdiff_t difference_type;
+// | pointer_traits<pointer>::difference_type difference_type;
// ...
// };
@@ -33,8 +33,30 @@
typedef T value_type;
};
+template <class T>
+struct C
+{
+ typedef T value_type;
+ struct pointer {};
+ struct const_pointer {};
+ struct void_pointer {};
+ struct const_void_pointer {};
+};
+
+namespace std
+{
+
+template <>
+struct pointer_traits<C<char>::pointer>
+{
+ typedef signed char difference_type;
+};
+
+}
+
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
+ static_assert((std::is_same<std::allocator_traits<C<char> >::difference_type, signed char>::value), "");
}
Modified: libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp?rev=119609&r1=119608&r2=119609&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp (original)
+++ libcxx/trunk/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp Wed Nov 17 19:40:00 2010
@@ -32,8 +32,32 @@
typedef T value_type;
};
+template <class T>
+struct C
+{
+ typedef T value_type;
+ struct pointer {};
+ struct const_pointer {};
+ struct void_pointer {};
+ struct const_void_pointer {};
+};
+
+namespace std
+{
+
+template <>
+struct pointer_traits<C<char>::pointer>
+{
+ typedef signed char difference_type;
+};
+
+}
+
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
- static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, std::size_t>::value), "");
+ static_assert((std::is_same<std::allocator_traits<B<char> >::size_type,
+ std::make_unsigned<std::ptrdiff_t>::type>::value), "");
+ static_assert((std::is_same<std::allocator_traits<C<char> >::size_type,
+ unsigned char>::value), "");
}
More information about the cfe-commits
mailing list