aboutsummaryrefslogtreecommitdiffhomepage
path: root/absl/memory
diff options
context:
space:
mode:
Diffstat (limited to 'absl/memory')
-rw-r--r--absl/memory/memory.h14
-rw-r--r--absl/memory/memory_test.cc14
2 files changed, 26 insertions, 2 deletions
diff --git a/absl/memory/memory.h b/absl/memory/memory.h
index 22d44b9..2220ee4 100644
--- a/absl/memory/memory.h
+++ b/absl/memory/memory.h
@@ -319,13 +319,23 @@ struct RebindPtr<T, U, void_t<typename T::template rebind<U>>> {
using type = typename T::template rebind<U>;
};
-template <typename T, typename U, typename = void>
+template <typename T, typename U>
+constexpr bool HasRebindAlloc(...) {
+ return false;
+}
+
+template <typename T, typename U>
+constexpr bool HasRebindAlloc(typename T::template rebind<U>::other*) {
+ return true;
+}
+
+template <typename T, typename U, bool = HasRebindAlloc<T, U>(nullptr)>
struct RebindAlloc {
using type = typename RebindFirstArg<T, U>::type;
};
template <typename T, typename U>
-struct RebindAlloc<T, U, void_t<typename T::template rebind<U>::other>> {
+struct RebindAlloc<T, U, true> {
using type = typename T::template rebind<U>::other;
};
diff --git a/absl/memory/memory_test.cc b/absl/memory/memory_test.cc
index 7d047ca..dee9b48 100644
--- a/absl/memory/memory_test.cc
+++ b/absl/memory/memory_test.cc
@@ -439,6 +439,20 @@ TEST(AllocatorTraits, Typedefs) {
}
template <typename T>
+struct AllocWithPrivateInheritance : private std::allocator<T> {
+ using value_type = T;
+};
+
+TEST(AllocatorTraits, RebindWithPrivateInheritance) {
+ // Regression test for some versions of gcc that do not like the sfinae we
+ // used in combination with private inheritance.
+ EXPECT_TRUE(
+ (std::is_same<AllocWithPrivateInheritance<int>,
+ absl::allocator_traits<AllocWithPrivateInheritance<char>>::
+ rebind_alloc<int>>::value));
+}
+
+template <typename T>
struct Rebound {};
struct AllocWithRebind {