aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-03-05 08:30:28 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-05 08:30:28 -0800
commitffa39e02bc34a33c23fcccd61b781b5d05a980d3 (patch)
tree332d51040f0e1d4e26645c5826149ecbfbf9874c
parentec7c0cec3f4d9360ad3d727728ab8b6cbf694e4e (diff)
sk_sp: fix contravariant constructors
TBR=reed This is obviously correct and needs to be fixed. Review URL: https://codereview.chromium.org/1771583002
-rw-r--r--include/core/SkRefCnt.h8
-rw-r--r--tests/RefCntTest.cpp16
2 files changed, 20 insertions, 4 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 9e8f3be61c..9b05ad4969 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -250,7 +250,7 @@ public:
*/
sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {}
template <typename U,
- typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value>>
sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {}
/**
@@ -260,7 +260,7 @@ public:
*/
sk_sp(sk_sp<T>&& that) : fPtr(that.release()) {}
template <typename U,
- typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value>>
sk_sp(sk_sp<U>&& that) : fPtr(that.release()) {}
/**
@@ -288,7 +288,7 @@ public:
return *this;
}
template <typename U,
- typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value>>
sk_sp<T>& operator=(const sk_sp<U>& that) {
this->reset(SkSafeRef(that.get()));
return *this;
@@ -304,7 +304,7 @@ public:
return *this;
}
template <typename U,
- typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value>>
sk_sp<T>& operator=(sk_sp<U>&& that) {
this->reset(that.release());
return *this;
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index 60a34ecf88..8914ccff49 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -274,3 +274,19 @@ DEF_TEST(sk_sp, reporter) {
check(reporter, 1, 2, 1, 1);
}
+namespace {
+struct FooAbstract : public SkRefCnt {
+ virtual void f() = 0;
+};
+struct FooConcrete : public FooAbstract {
+ void f() override {}
+};
+}
+static sk_sp<FooAbstract> make_foo() {
+ // can not cast FooConcrete to FooAbstract.
+ // can cast FooConcrete* to FooAbstract*.
+ return sk_make_sp<FooConcrete>();
+}
+DEF_TEST(sk_make_sp, r) {
+ auto x = make_foo();
+}