From 48b5b855934be341c02139c0bed88c35c1b40d8f Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Tue, 13 Apr 2010 09:21:31 -0400 Subject: Add a warning when variables are used uninitialized. --- Source/cmCommandArgumentParserHelper.cxx | 7 ++++++- Source/cmMakefile.cxx | 11 +++++++++++ Source/cmMakefile.h | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 234c37e..027a2ba 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -119,10 +119,15 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) cmOStringStream ostr; ostr << this->FileLine; return this->AddString(ostr.str().c_str()); - } + } const char* value = this->Makefile->GetDefinition(var); if(!value && !this->RemoveEmpty) { + if(!this->Makefile->VariableCleared(var)) + { + std::cerr << this->FileName << ":" << this->FileLine << ":" << + " warning: uninitialized variable \'" << var << "\'\n"; + } return 0; } if (this->EscapeQuotes && value) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8eece6b..c56641c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -43,6 +43,7 @@ class cmMakefile::Internals { public: std::stack > VarStack; + std::set VarRemoved; }; // default is not to be building executables @@ -1694,9 +1695,19 @@ void cmMakefile::AddDefinition(const char* name, bool value) #endif } +bool cmMakefile::VariableCleared(const char* var) const +{ + if(this->Internal->VarRemoved.find(var) != this->Internal->VarRemoved.end()) + { + return true; + } + return false; +} + void cmMakefile::RemoveDefinition(const char* name) { this->Internal->VarStack.top().Set(name, 0); + this->Internal->VarRemoved.insert(name); #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* vv = this->GetVariableWatch(); if ( vv ) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 4fae7ee..daeab83 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -61,6 +61,10 @@ public: unsigned int GetCacheMajorVersion(); unsigned int GetCacheMinorVersion(); + /* return true if a variable has been set with + set(foo ) + */ + bool VariableCleared(const char* ) const; /** Return whether compatibility features needed for a version of the cache or lower should be enabled. */ bool NeedCacheCompatibility(int major, int minor); -- cgit v0.12