aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/private/SkTemplates.h6
-rw-r--r--tests/TemplatesTest.cpp17
2 files changed, 21 insertions, 2 deletions
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 351fcccfc3..919d160d0d 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -294,8 +294,10 @@ public:
}
SkAutoTMalloc& operator=(SkAutoTMalloc<T>&& that) {
- sk_free(fPtr);
- fPtr = that.release();
+ if (this != &that) {
+ sk_free(fPtr);
+ fPtr = that.release();
+ }
return *this;
}
diff --git a/tests/TemplatesTest.cpp b/tests/TemplatesTest.cpp
index fc3bc320af..9d5ca7735f 100644
--- a/tests/TemplatesTest.cpp
+++ b/tests/TemplatesTest.cpp
@@ -126,3 +126,20 @@ DEF_TEST(AutoReallocToZero, reporter) {
test_realloc_to_zero<SkAutoTMalloc<int> >(reporter);
test_realloc_to_zero<SkAutoSTMalloc<kStackPreallocCount, int> >(reporter);
}
+
+DEF_TEST(SkAutoTMallocSelfMove, r) {
+#if defined(__clang__)
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wself-move"
+#endif
+
+ SkAutoTMalloc<int> foo(20);
+ REPORTER_ASSERT(r, foo.get());
+
+ foo = std::move(foo);
+ REPORTER_ASSERT(r, foo.get());
+
+#if defined(__clang__)
+ #pragma clang diagnostic pop
+#endif
+}