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.
This commit is contained in:
Georg Baum 2015-10-11 11:16:09 +02:00
parent 74be166499
commit cea2d71e64
7 changed files with 48 additions and 0 deletions

View File

@ -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)

View File

@ -39,6 +39,8 @@ public:
///
InsetCommand(InsetCommand const & rhs);
///
InsetCommand & operator=(InsetCommand const & rhs);
///
virtual ~InsetCommand();
///
InsetCommand * asInsetCommand() { return this; }

View File

@ -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";

View File

@ -36,6 +36,8 @@ public:
~InsetIPA();
///
InsetIPA(InsetIPA const & other);
///
InsetIPA & operator=(InsetIPA const & other);
/// \name Methods inherited from Inset class
//@{

View File

@ -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 &);

View File

@ -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";

View File

@ -36,6 +36,8 @@ public:
~InsetPreview();
///
InsetPreview(InsetPreview const & other);
///
InsetPreview & operator=(InsetPreview const & other);
/// \name Methods inherited from Inset class
//@{