diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 8bad1a456..f36eb7477 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -104,7 +104,8 @@ bool cmFunctionHelperCommand::InvokeInitialPass } // we push a scope on the makefile - this->Makefile->PushScope(); + cmMakefile::ScopePushPop varScope(this->Makefile); + static_cast(varScope); // set the value of argc cmOStringStream strStream; @@ -167,13 +168,11 @@ bool cmFunctionHelperCommand::InvokeInitialPass } if (status.GetReturnInvoked()) { - this->Makefile->PopScope(); return true; } } // pop scope on the makefile - this->Makefile->PopScope(); return true; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c0e0bf44c..c77fcdbca 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -780,6 +780,16 @@ public: void PopScope(); void RaiseScope(const char *var, const char *value); + /** Helper class to push and pop scopes automatically. */ + class ScopePushPop + { + public: + ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); } + ~ScopePushPop() { this->Makefile->PopScope(); } + private: + cmMakefile* Makefile; + }; + void IssueMessage(cmake::MessageType t, std::string const& text) const;