From: Václav Slavík Date: Sun, 24 Apr 2011 13:14:47 +0000 (+0000) Subject: Don't rely on RVO in wxON_BLOCK_EXIT_SET(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/aef081f465d68fabbf9e7abc0c57ea745b6fd55a?ds=inline 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 --- diff --git a/include/wx/scopeguard.h b/include/wx/scopeguard.h index a68c9896d8..434c89768d 100644 --- a/include/wx/scopeguard.h +++ b/include/wx/scopeguard.h @@ -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;