check for self-assignment in operator=
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51123 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c6ed07281f
commit
162e998c2f
@ -68,7 +68,8 @@ public:
|
||||
|
||||
wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry)
|
||||
{
|
||||
Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item);
|
||||
if (&entry != this)
|
||||
Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,12 @@ public:
|
||||
|
||||
wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
|
||||
{
|
||||
if ( m_owned )
|
||||
free(m_str);
|
||||
CopyFrom(src);
|
||||
if (&src != this)
|
||||
{
|
||||
if ( m_owned )
|
||||
free(m_str);
|
||||
CopyFrom(src);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -317,9 +320,12 @@ public:
|
||||
|
||||
wxMemoryBuffer& operator=(const wxMemoryBuffer& src)
|
||||
{
|
||||
m_bufdata->DecRef();
|
||||
m_bufdata = src.m_bufdata;
|
||||
m_bufdata->IncRef();
|
||||
if (&src != this)
|
||||
{
|
||||
m_bufdata->DecRef();
|
||||
m_bufdata = src.m_bufdata;
|
||||
m_bufdata->IncRef();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -87,17 +87,20 @@ public:
|
||||
|
||||
wxFontData& operator=(const wxFontData& data)
|
||||
{
|
||||
wxObject::operator=(data);
|
||||
m_fontColour = data.m_fontColour;
|
||||
m_showHelp = data.m_showHelp;
|
||||
m_allowSymbols = data.m_allowSymbols;
|
||||
m_enableEffects = data.m_enableEffects;
|
||||
m_initialFont = data.m_initialFont;
|
||||
m_chosenFont = data.m_chosenFont;
|
||||
m_minSize = data.m_minSize;
|
||||
m_maxSize = data.m_maxSize;
|
||||
m_encoding = data.m_encoding;
|
||||
m_encodingInfo = data.m_encodingInfo;
|
||||
if (&data != this)
|
||||
{
|
||||
wxObject::operator=(data);
|
||||
m_fontColour = data.m_fontColour;
|
||||
m_showHelp = data.m_showHelp;
|
||||
m_allowSymbols = data.m_allowSymbols;
|
||||
m_enableEffects = data.m_enableEffects;
|
||||
m_initialFont = data.m_initialFont;
|
||||
m_chosenFont = data.m_chosenFont;
|
||||
m_minSize = data.m_minSize;
|
||||
m_maxSize = data.m_maxSize;
|
||||
m_encoding = data.m_encoding;
|
||||
m_encodingInfo = data.m_encodingInfo;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -334,11 +334,6 @@ public: \
|
||||
name() { } \
|
||||
~name() { } \
|
||||
\
|
||||
name& operator=(const name& src) \
|
||||
{ base* temp = (base*) this; \
|
||||
(*temp) = ((const base&)src); \
|
||||
return *this; } \
|
||||
\
|
||||
T& operator[](size_t uiIndex) const \
|
||||
{ return (T&)(base::operator[](uiIndex)); } \
|
||||
T& Item(size_t uiIndex) const \
|
||||
|
@ -778,7 +778,7 @@ public:
|
||||
|
||||
virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
|
||||
|
||||
wxMouseEvent& operator=(const wxMouseEvent& event) { Assign(event); return *this; }
|
||||
wxMouseEvent& operator=(const wxMouseEvent& event) { if (&event != this) Assign(event); return *this; }
|
||||
|
||||
public:
|
||||
wxCoord m_x, m_y;
|
||||
@ -940,22 +940,24 @@ public:
|
||||
// example)
|
||||
wxKeyEvent& operator=(const wxKeyEvent& evt)
|
||||
{
|
||||
m_x = evt.m_x;
|
||||
m_y = evt.m_y;
|
||||
if (&evt != this)
|
||||
{
|
||||
m_x = evt.m_x;
|
||||
m_y = evt.m_y;
|
||||
|
||||
m_keyCode = evt.m_keyCode;
|
||||
m_keyCode = evt.m_keyCode;
|
||||
|
||||
m_controlDown = evt.m_controlDown;
|
||||
m_shiftDown = evt.m_shiftDown;
|
||||
m_altDown = evt.m_altDown;
|
||||
m_metaDown = evt.m_metaDown;
|
||||
m_scanCode = evt.m_scanCode;
|
||||
m_rawCode = evt.m_rawCode;
|
||||
m_rawFlags = evt.m_rawFlags;
|
||||
m_controlDown = evt.m_controlDown;
|
||||
m_shiftDown = evt.m_shiftDown;
|
||||
m_altDown = evt.m_altDown;
|
||||
m_metaDown = evt.m_metaDown;
|
||||
m_scanCode = evt.m_scanCode;
|
||||
m_rawCode = evt.m_rawCode;
|
||||
m_rawFlags = evt.m_rawFlags;
|
||||
#if wxUSE_UNICODE
|
||||
m_uniChar = evt.m_uniChar;
|
||||
m_uniChar = evt.m_uniChar;
|
||||
#endif
|
||||
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -2284,7 +2286,7 @@ protected:
|
||||
|
||||
private:
|
||||
// It makes no sense to copy objects of this class
|
||||
wxEventConnectionRef& operator = (const wxEventConnectionRef& WXUNUSED(other)) { wxASSERT(0); return *this; }
|
||||
wxEventConnectionRef& operator = (const wxEventConnectionRef& WXUNUSED(other)) { wxFAIL; return *this; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,7 +30,14 @@ public:
|
||||
wxDataFormat( const wxCStrData& id ) { InitFromString(id); }
|
||||
|
||||
wxDataFormat& operator=(const wxDataFormat& format)
|
||||
{ m_type = format.m_type; m_format = format.m_format; return *this; }
|
||||
{
|
||||
if (&format != this)
|
||||
{
|
||||
m_type = format.m_type;
|
||||
m_format = format.m_format;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
wxDataFormat& operator=(NativeFormat format)
|
||||
{ SetId(format); return *this; }
|
||||
|
||||
|
@ -161,7 +161,7 @@ public: \
|
||||
\
|
||||
Iterator() : m_node(0), m_ht(0) {} \
|
||||
Iterator( Node* node, const Self* ht ) \
|
||||
: m_node(node), m_ht((Self*)ht) {} \
|
||||
: m_node(node), m_ht(wx_const_cast(Self*, ht)) {} \
|
||||
bool operator ==( const Iterator& it ) const \
|
||||
{ return m_node == it.m_node; } \
|
||||
bool operator !=( const Iterator& it ) const \
|
||||
@ -204,7 +204,7 @@ public: \
|
||||
const_iterator() : Iterator() {} \
|
||||
const_iterator(iterator i) : Iterator(i) {} \
|
||||
const_iterator( Node* node, const Self* ht ) \
|
||||
: Iterator( node, (Self*)ht ) {} \
|
||||
: Iterator(node, wx_const_cast(Self*, ht)) {} \
|
||||
const_iterator& operator++() { PlusPlus();return *this; } \
|
||||
const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
|
||||
const_reference operator *() const { return m_node->m_value; } \
|
||||
@ -236,12 +236,15 @@ public: \
|
||||
\
|
||||
const Self& operator=( const Self& ht ) \
|
||||
{ \
|
||||
clear(); \
|
||||
m_hasher = ht.m_hasher; \
|
||||
m_equals = ht.m_equals; \
|
||||
m_getKey = ht.m_getKey; \
|
||||
m_items = ht.m_items; \
|
||||
HashCopy( ht ); \
|
||||
if (&ht != this) \
|
||||
{ \
|
||||
clear(); \
|
||||
m_hasher = ht.m_hasher; \
|
||||
m_equals = ht.m_equals; \
|
||||
m_getKey = ht.m_getKey; \
|
||||
m_items = ht.m_items; \
|
||||
HashCopy( ht ); \
|
||||
} \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
@ -407,7 +410,8 @@ public: \
|
||||
typedef const KEY_T const_t1; \
|
||||
typedef const VALUE_T const_t2; \
|
||||
\
|
||||
CLASSNAME( const const_t1& f, const const_t2& s ):first(t1(f)),second(t2(s)) {} \
|
||||
CLASSNAME(const const_t1& f, const const_t2& s) \
|
||||
: first(wx_const_cast(t1&, f)), second(wx_const_cast(t2&, s)) {} \
|
||||
\
|
||||
t1 first; \
|
||||
t2 second; \
|
||||
|
@ -22,8 +22,8 @@
|
||||
like the old class.
|
||||
*/
|
||||
|
||||
#ifndef _WX_LISTH__
|
||||
#define _WX_LISTH__
|
||||
#ifndef _WX_LIST_H_
|
||||
#define _WX_LIST_H_
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// headers
|
||||
@ -469,7 +469,7 @@ protected:
|
||||
virtual void DeleteData() { }
|
||||
public:
|
||||
// for wxList::iterator
|
||||
void** GetDataPtr() const { return &(((wxNodeBase*)this)->m_data); }
|
||||
void** GetDataPtr() const { return &(wx_const_cast(wxNodeBase*, this)->m_data); }
|
||||
private:
|
||||
// optional key stuff
|
||||
wxListKeyValue m_key;
|
||||
@ -732,7 +732,7 @@ private:
|
||||
: wxListBase(count, (void **)elements) { } \
|
||||
\
|
||||
name& operator=(const name& list) \
|
||||
{ Assign(list); return *this; } \
|
||||
{ if (&list != this) Assign(list); return *this; } \
|
||||
\
|
||||
nodetype *GetFirst() const \
|
||||
{ return (nodetype *)wxListBase::GetFirst(); } \
|
||||
@ -1178,7 +1178,7 @@ public:
|
||||
|
||||
#if !wxUSE_STL
|
||||
wxList& operator=(const wxList& list)
|
||||
{ Assign(list); return *this; }
|
||||
{ if (&list != this) Assign(list); return *this; }
|
||||
|
||||
// compatibility methods
|
||||
void Sort(wxSortCompareFunction compfunc) { wxListBase::Sort(compfunc); }
|
||||
@ -1214,7 +1214,14 @@ public:
|
||||
// inefficient!)
|
||||
wxStringList(const wxStringList& other) : wxStringListBase() { DeleteContents(true); DoCopy(other); }
|
||||
wxStringList& operator=(const wxStringList& other)
|
||||
{ Clear(); DoCopy(other); return *this; }
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
Clear();
|
||||
DoCopy(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// operations
|
||||
// makes a copy of the string
|
||||
|
@ -657,7 +657,14 @@ public:
|
||||
iterator(const iterator& i)
|
||||
: m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
|
||||
iterator& operator=(const iterator& i)
|
||||
{ m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
|
||||
{
|
||||
if (&i != this)
|
||||
{
|
||||
m_cur = i.m_cur;
|
||||
m_node.set(i.str(), &m_cur);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference operator*()
|
||||
{ return wxUniCharRef::CreateForString(m_node, m_cur); }
|
||||
@ -692,7 +699,14 @@ public:
|
||||
: m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
|
||||
|
||||
const_iterator& operator=(const const_iterator& i)
|
||||
{ m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
|
||||
{
|
||||
if (&i != this)
|
||||
{
|
||||
m_cur = i.m_cur;
|
||||
m_node.set(i.str(), &m_cur);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator=(const iterator& i)
|
||||
{ m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
|
||||
|
||||
@ -1324,7 +1338,7 @@ public:
|
||||
// overloaded assignment
|
||||
// from another wxString
|
||||
wxString& operator=(const wxString& stringSrc)
|
||||
{ m_impl = stringSrc.m_impl; return *this; }
|
||||
{ if (&stringSrc != this) m_impl = stringSrc.m_impl; return *this; }
|
||||
wxString& operator=(const wxCStrData& cstr)
|
||||
{ return *this = cstr.AsString(); }
|
||||
// from a character
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
bool operator&&(bool v) const { return (bool)*this && v; }
|
||||
|
||||
// Assignment operators:
|
||||
wxUniChar& operator=(const wxUniChar& c) { m_value = c.m_value; return *this; }
|
||||
wxUniChar& operator=(const wxUniChar& c) { if (&c != this) m_value = c.m_value; return *this; }
|
||||
wxUniChar& operator=(const wxUniCharRef& c);
|
||||
wxUniChar& operator=(char c) { m_value = From8bit(c); return *this; }
|
||||
wxUniChar& operator=(unsigned char c) { m_value = From8bit((char)c); return *this; }
|
||||
@ -218,7 +218,7 @@ public:
|
||||
#endif
|
||||
|
||||
wxUniCharRef& operator=(const wxUniCharRef& c)
|
||||
{ return *this = c.UniChar(); }
|
||||
{ if (&c != this) *this = c.UniChar(); return *this; }
|
||||
|
||||
wxUniCharRef& operator=(char c) { return *this = wxUniChar(c); }
|
||||
wxUniCharRef& operator=(unsigned char c) { return *this = wxUniChar(c); }
|
||||
|
@ -9,8 +9,8 @@
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_UTILSH__
|
||||
#define _WX_UTILSH__
|
||||
#ifndef _WX_UTILS_H_
|
||||
#define _WX_UTILS_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
@ -136,7 +136,7 @@ class WXDLLIMPEXP_BASE wxPlatform
|
||||
public:
|
||||
wxPlatform() { Init(); }
|
||||
wxPlatform(const wxPlatform& platform) { Copy(platform); }
|
||||
void operator = (const wxPlatform& platform) { Copy(platform); }
|
||||
void operator = (const wxPlatform& platform) { if (&platform != this) Copy(platform); }
|
||||
void Copy(const wxPlatform& platform);
|
||||
|
||||
// Specify an optional default value
|
||||
|
@ -72,7 +72,8 @@ public:
|
||||
|
||||
wxWindowIDRef& operator=(const wxWindowIDRef& id)
|
||||
{
|
||||
Assign(id.m_id);
|
||||
if (&id != this)
|
||||
Assign(id.m_id);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user