From a90a576d76faff2ab8b14186737edd7fc12f076f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D1=83=D0=BD=20=D0=92=D0=B8=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80?= Date: Mon, 14 Mar 2016 16:10:23 +0300 Subject: [PATCH] fixed incorrect behaviour of move semantics for cv::Ptr, cv::Mat, cv::UMat in case when rvalue-reference references to *this. --- modules/core/include/opencv2/core/mat.inl.hpp | 5 +++++ modules/core/include/opencv2/core/ptr.inl.hpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 1fb32b3d2c..40453b8e0a 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1165,6 +1165,9 @@ Mat::Mat(Mat&& m) inline Mat& Mat::operator = (Mat&& m) { + if (this == &m) + return *this; + release(); flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; @@ -3599,6 +3602,8 @@ UMat::UMat(UMat&& m) inline UMat& UMat::operator = (UMat&& m) { + if (this == &m) + return *this; release(); flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; allocator = m.allocator; usageFlags = m.usageFlags; diff --git a/modules/core/include/opencv2/core/ptr.inl.hpp b/modules/core/include/opencv2/core/ptr.inl.hpp index 3f6f214a8f..d33aca988b 100644 --- a/modules/core/include/opencv2/core/ptr.inl.hpp +++ b/modules/core/include/opencv2/core/ptr.inl.hpp @@ -264,6 +264,9 @@ Ptr::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored) template Ptr& Ptr::operator = (Ptr&& o) { + if (this == &o) + return *this; + release(); owner = o.owner; stored = o.stored;