diff options
author | tzik <tzik@chromium.org> | 2016-03-16 00:20:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-16 07:21:05 +0000 |
commit | 8df3dd0df5b731da6db74c8a3033ef827f3e5c4b (patch) | |
tree | 91c60337f50f9b337585159347cc42eb83174eac /base | |
parent | 4ccd1db7b8d6ac5b2e45b2fa9ff42ffe0ab33b39 (diff) | |
download | chromium_src-8df3dd0df5b731da6db74c8a3033ef827f3e5c4b.zip chromium_src-8df3dd0df5b731da6db74c8a3033ef827f3e5c4b.tar.gz chromium_src-8df3dd0df5b731da6db74c8a3033ef827f3e5c4b.tar.bz2 |
Use std::is_base_of to assert WeakPtr is used correctly
SupportsWeakPtr::StaticAsWeakPtr used to use std::is_convertible to
ensure the argument is derived fromSupportsWeakPtrBase.
However, the assertion fails also when the class has multiple
SupportWeakPtrBases as its ancestor, and in this case the error message
from static_assert is inaccurate.
Also, it doesn't match to base_nocompile_tests expectation.
This CL replaces the std::is_convertible with std::is_base_of and
updates base_nocompile_tests expectation.
Review URL: https://codereview.chromium.org/1805503002
Cr-Commit-Position: refs/heads/master@{#381415}
Diffstat (limited to 'base')
-rw-r--r-- | base/memory/weak_ptr.h | 7 | ||||
-rw-r--r-- | base/memory/weak_ptr_unittest.nc | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h index 9ba5e25..006e1fd 100644 --- a/base/memory/weak_ptr.h +++ b/base/memory/weak_ptr.h @@ -161,10 +161,9 @@ class SupportsWeakPtrBase { // function that makes calling this easier. template<typename Derived> static WeakPtr<Derived> StaticAsWeakPtr(Derived* t) { - using convertible = - std::is_convertible<Derived*, internal::SupportsWeakPtrBase*>; - static_assert(convertible::value, - "AsWeakPtr argument must inherit from SupportsWeakPtr"); + static_assert( + std::is_base_of<internal::SupportsWeakPtrBase, Derived>::value, + "AsWeakPtr argument must inherit from SupportsWeakPtr"); return AsWeakPtrImpl<Derived>(t, *t); } diff --git a/base/memory/weak_ptr_unittest.nc b/base/memory/weak_ptr_unittest.nc index bad1c97..32deca9 100644 --- a/base/memory/weak_ptr_unittest.nc +++ b/base/memory/weak_ptr_unittest.nc @@ -129,7 +129,7 @@ void WontCompile() { WeakPtr<Unrelated> ptr = AsWeakPtr(&f); } -#elif defined(NCTEST_AMBIGUOUS_ANCESTORS) // [r"fatal error: ambiguous conversion from derived class 'base::MultiplyDerivedProducer' to base class 'base::internal::SupportsWeakPtrBase':"] +#elif defined(NCTEST_AMBIGUOUS_ANCESTORS) // [r"fatal error: member 'AsWeakPtr' found in multiple base classes of different types"] void WontCompile() { MultiplyDerivedProducer f; |