Commit 7cc71cfc authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

base/memory: Remove base::internal::DereferencedPointerType

Replaces base::internal::DereferencedPointerType with the std
templates in <type_traits>.

Bug: 1073933
Change-Id: I108fc52d5f3834b0749f95342a76578ef1c10306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302880Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBartek Nowierski <bartekn@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790318}
parent fab7469d
...@@ -343,15 +343,6 @@ struct CheckedPtr2OrMTEImpl { ...@@ -343,15 +343,6 @@ struct CheckedPtr2OrMTEImpl {
#endif // defined(ARCH_CPU_64_BITS) && !defined(OS_NACL) #endif // defined(ARCH_CPU_64_BITS) && !defined(OS_NACL)
template <typename T>
struct DereferencedPointerType {
using Type = decltype(*std::declval<T*>());
};
// This explicitly doesn't define any type aliases, since dereferencing void is
// invalid.
template <>
struct DereferencedPointerType<void> {};
} // namespace internal } // namespace internal
// DO NOT USE! EXPERIMENTAL ONLY! This is helpful for local testing! // DO NOT USE! EXPERIMENTAL ONLY! This is helpful for local testing!
...@@ -423,11 +414,10 @@ class CheckedPtr { ...@@ -423,11 +414,10 @@ class CheckedPtr {
return wrapped_ptr_ != Impl::GetWrappedNullPtr(); return wrapped_ptr_ != Impl::GetWrappedNullPtr();
} }
// Use SFINAE to avoid defining |operator*| for T=void, which wouldn't compile
// due to |void&|.
template <typename U = T, template <typename U = T,
typename V = typename internal::DereferencedPointerType<U>::Type> typename Unused = std::enable_if_t<
ALWAYS_INLINE V& operator*() const { !std::is_void<typename std::remove_cv<U>::type>::value>>
ALWAYS_INLINE U& operator*() const {
return *GetForDereference(); return *GetForDereference();
} }
ALWAYS_INLINE T* operator->() const { return GetForDereference(); } ALWAYS_INLINE T* operator->() const { return GetForDereference(); }
......
...@@ -73,7 +73,7 @@ void WontCompile() { ...@@ -73,7 +73,7 @@ void WontCompile() {
std::ignore = static_cast<Unrelated*>(ptr); std::ignore = static_cast<Unrelated*>(ptr);
} }
#elif defined(NCTEST_VOID_DEREFERENCE) // [r"ISO C\+\+ does not allow indirection on operand of type 'const void \*' \[-Wvoid-ptr-dereference\]"] #elif defined(NCTEST_VOID_DEREFERENCE) // [r"indirection requires pointer operand \('CheckedPtr<const void>' invalid\)"]
void WontCompile() { void WontCompile() {
const char foo[] = "42"; const char foo[] = "42";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment