From cea2d71e641e6a4023128a367d1cd5a593ed1706 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 11 Oct 2015 11:16:09 +0200 Subject: [PATCH] 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. --- src/insets/InsetCommand.cpp | 14 ++++++++++++++ src/insets/InsetCommand.h | 2 ++ src/insets/InsetIPA.cpp | 12 ++++++++++++ src/insets/InsetIPA.h | 2 ++ src/insets/InsetInclude.h | 4 ++++ src/insets/InsetPreview.cpp | 12 ++++++++++++ src/insets/InsetPreview.h | 2 ++ 7 files changed, 48 insertions(+) diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index dadab6ab93..dbbaed1253 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 ae6fc3ec05..1be72a8ec8 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 e1f5729914..8bc3d46eec 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 f100c663f9..b3b90ee433 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 ce93c7104c..78d308008c 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 b8fd0aea8c..d327fe5b52 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 15380ba543..a7076c4b6f 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 //@{ -- 2.39.2