commit cea2d71e641e6a4023128a367d1cd5a593ed1706
Author: Georg Baum <[email protected]>
Date: Sun Oct 11 11:16:09 2015 +0200
Comply with rule-of-three
The rule-of-three says that if any of virtual destructor, copy constructor
or assignment operator needs to be manually implemented, then all three
should be implemented. Otherwise you can get subtle bugs which can be
difficult to find. In the changed classes, changing a copy-construction to
an assignment would have had surprising effects. Now they all behave
consistently.
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index dadab6a..dbbaed1 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -65,6 +65,20 @@ InsetCommand::InsetCommand(InsetCommand const & rhs)
{}
+InsetCommand & InsetCommand::operator=(InsetCommand const & rhs)
+{
+ if (&rhs == this)
+ return *this;
+
+ Inset::operator=(rhs);
+ p_ = rhs.p_;
+ mouse_hover_.clear();
+ button_ = RenderButton();
+
+ return *this;
+}
+
+
InsetCommand::~InsetCommand()
{
if (p_.code() != NO_CODE)
diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h
index ae6fc3e..1be72a8 100644
--- a/src/insets/InsetCommand.h
+++ b/src/insets/InsetCommand.h
@@ -39,6 +39,8 @@ public:
///
InsetCommand(InsetCommand const & rhs);
///
+ InsetCommand & operator=(InsetCommand const & rhs);
+ ///
virtual ~InsetCommand();
///
InsetCommand * asInsetCommand() { return this; }
diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp
index e1f5729..8bc3d46 100644
--- a/src/insets/InsetIPA.cpp
+++ b/src/insets/InsetIPA.cpp
@@ -54,6 +54,18 @@ InsetIPA::InsetIPA(InsetIPA const & other)
}
+InsetIPA & InsetIPA::operator=(InsetIPA const & other)
+{
+ if (&other == this)
+ return *this;
+
+ InsetText::operator=(other);
+ preview_.reset(new RenderPreview(*other.preview_, this));
+
+ return *this;
+}
+
+
void InsetIPA::write(ostream & os) const
{
os << "IPA" << "\n";
diff --git a/src/insets/InsetIPA.h b/src/insets/InsetIPA.h
index f100c66..b3b90ee 100644
--- a/src/insets/InsetIPA.h
+++ b/src/insets/InsetIPA.h
@@ -36,6 +36,8 @@ public:
~InsetIPA();
///
InsetIPA(InsetIPA const & other);
+ ///
+ InsetIPA & operator=(InsetIPA const & other);
/// \name Methods inherited from Inset class
//@{
diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h
index ce93c71..78d3080 100644
--- a/src/insets/InsetInclude.h
+++ b/src/insets/InsetInclude.h
@@ -35,6 +35,10 @@ namespace support {
/// for including tex/lyx files
class InsetInclude : public InsetCommand {
+ // Disable assignment operator, since it is not used, and cannot be
+ // implemented consistently with the copy constructor, because
+ // include_label is const.
+ InsetInclude & operator=(InsetInclude const &);
public:
///
InsetInclude(Buffer * buf, InsetCommandParams const &);
diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp
index b8fd0ae..d327fe5 100644
--- a/src/insets/InsetPreview.cpp
+++ b/src/insets/InsetPreview.cpp
@@ -54,6 +54,18 @@ InsetPreview::InsetPreview(InsetPreview const & other)
}
+InsetPreview & InsetPreview::operator=(InsetPreview const & other)
+{
+ if (&other == this)
+ return *this;
+
+ InsetText::operator=(other);
+ preview_.reset(new RenderPreview(*other.preview_, this));
+
+ return *this;
+}
+
+
void InsetPreview::write(ostream & os) const
{
os << "Preview" << "\n";
diff --git a/src/insets/InsetPreview.h b/src/insets/InsetPreview.h
index 15380ba..a7076c4 100644
--- a/src/insets/InsetPreview.h
+++ b/src/insets/InsetPreview.h
@@ -36,6 +36,8 @@ public:
~InsetPreview();
///
InsetPreview(InsetPreview const & other);
+ ///
+ InsetPreview & operator=(InsetPreview const & other);
/// \name Methods inherited from Inset class
//@{