From 71e0f7e24d506f4120991730d13910587df3f15f Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 22 Aug 2024 17:55:52 +0200 Subject: [PATCH] Wizards: Add move semantics to shared data class template Fixes: QTCREATORBUG-30526 Change-Id: I9a3423fcbbc19a26876bf1d6c863285639449df3 Reviewed-by: Fabian Kosmale --- .../templates/wizards/classes/cpp/file.cpp | 20 ++++++++++++++++++- .../templates/wizards/classes/cpp/file.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/share/qtcreator/templates/wizards/classes/cpp/file.cpp b/share/qtcreator/templates/wizards/classes/cpp/file.cpp index 760f19c2e7b..57f55f2bbb4 100644 --- a/share/qtcreator/templates/wizards/classes/cpp/file.cpp +++ b/share/qtcreator/templates/wizards/classes/cpp/file.cpp @@ -1,5 +1,10 @@ %{JS: Cpp.licenseTemplate()}\ #include "%{JS: Util.relativeFilePath('%{Path}/%{HdrFileName}', '%{Path}' + '/' + Util.path('%{SrcFileName}'))}" + +@if '%{IncludeQSharedData}' +#include + +@endif %{JS: Cpp.openNamespaces('%{Class}')} @if '%{IncludeQSharedData}' class %{CN}Data : public QSharedData @@ -32,10 +37,23 @@ public: } +%{CN}::%{CN}(%{CN} &&rhs) + : data{std::move(rhs.data)} +{ + +} + %{CN} &%{CN}::operator=(const %{CN} &rhs) { if (this != &rhs) - data.operator=(rhs.data); + data = rhs.data; + return *this; +} + +%{CN} &%{CN}::operator=(%{CN} &&rhs) +{ + if (this != &rhs) + data = std::move(rhs.data); return *this; } diff --git a/share/qtcreator/templates/wizards/classes/cpp/file.h b/share/qtcreator/templates/wizards/classes/cpp/file.h index 5dac9614e26..beaa86548f4 100644 --- a/share/qtcreator/templates/wizards/classes/cpp/file.h +++ b/share/qtcreator/templates/wizards/classes/cpp/file.h @@ -44,7 +44,9 @@ public: @endif @if '%{IncludeQSharedData}' %{CN}(const %{CN} &); + %{CN}(%{CN} &&); %{CN} &operator=(const %{CN} &); + %{CN} &operator=(%{CN} &&); ~%{CN}(); @endif @if %{isQObject}