OSDN Git Service

Correct value_type for some TrackingAllocators.
authorDan Albert <danalbert@google.com>
Tue, 12 Jan 2016 22:23:14 +0000 (14:23 -0800)
committerDan Albert <danalbert@google.com>
Tue, 12 Jan 2016 22:23:14 +0000 (14:23 -0800)
The standard says that the value_type for the allocator of a
map/multimap must be std::pair<const Key, T>. These instances were not
properly carrying the const, and the updated version of libc++ has a
static_assert to make sure that map::allocator_type and
allocator::value_type really do match (as mismatches will tickle
undefined behavior in libc++).

Change-Id: I7a3a49fccea4ecc4579929d9ddd7872c62b60f5f

runtime/base/allocator.h
runtime/safe_map.h

index 969f5b9..cea7046 100644 (file)
@@ -158,7 +158,7 @@ using TrackingAllocator = typename TypeStaticIf<kEnableTrackingAllocator,
 
 template<class Key, class T, AllocatorTag kTag, class Compare = std::less<Key>>
 using AllocationTrackingMultiMap = std::multimap<
-    Key, T, Compare, TrackingAllocator<std::pair<Key, T>, kTag>>;
+    Key, T, Compare, TrackingAllocator<std::pair<const Key, T>, kTag>>;
 
 template<class Key, AllocatorTag kTag, class Compare = std::less<Key>>
 using AllocationTrackingSet = std::set<Key, Compare, TrackingAllocator<Key, kTag>>;
index 4e62dda..a8b48ee 100644 (file)
@@ -146,7 +146,7 @@ bool operator!=(const SafeMap<K, V, Comparator, Allocator>& lhs,
 
 template<class Key, class T, AllocatorTag kTag, class Compare = std::less<Key>>
 class AllocationTrackingSafeMap : public SafeMap<
-    Key, T, Compare, TrackingAllocator<std::pair<Key, T>, kTag>> {
+    Key, T, Compare, TrackingAllocator<std::pair<const Key, T>, kTag>> {
 };
 
 }  // namespace art