Don't rely on RVO in wxON_BLOCK_EXIT_SET().

MakeVarSetter() relies on the compiler always using RVO, as
VariableSetterImpl<> doesn't have correct copy ctor; worse yet, its use
wasn't detected at compile time.  With some compilers (e.g. VC++ 2008
with non-trivial variable types), this resulted in the variable being
reset too soon, immediately in the place where the macro was used.
Fixed by using the same technique already used in wxScopeGuardImpl. In
fact, VariableSetterImpl is just another special case of
wxScopeGuardImpl, so just derive from the latter.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67592 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2011-04-24 13:14:47 +00:00
parent da87ce5a36
commit aef081f465

View File

@@ -390,7 +390,7 @@ namespace wxPrivate
{
// empty class just to be able to define a reference to it
class VariableSetterBase { };
class VariableSetterBase : public wxScopeGuardImplBase { };
typedef const VariableSetterBase& VariableSetter;
@@ -404,10 +404,9 @@ public:
{
}
~VariableSetterImpl()
{
m_var = m_value;
}
~VariableSetterImpl() { wxPrivateOnScopeExit(*this); }
void Execute() { m_var = m_value; }
private:
T& m_var;
@@ -426,10 +425,9 @@ public:
{
}
~VariableNullerImpl()
{
m_var = NULL;
}
~VariableNullerImpl() { wxPrivateOnScopeExit(*this); }
void Execute() { m_var = NULL; }
private:
T& m_var;