summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorArtur Ryt <artur.ryt@gmail.com>2018-12-13 19:45:17 (GMT)
committerCraig Scott <craig.scott@crascit.com>2018-12-29 21:31:09 (GMT)
commitcbf0c0fce4dfe23912f7cc012c6f0234a5fd694b (patch)
tree39a75140d073d822c226a5caa19d4cb0769781bb /Source
parent1d32a35c10b384e8eb0dd2ce68c7bd11424409ac (diff)
downloadCMake-cbf0c0fce4dfe23912f7cc012c6f0234a5fd694b.zip
CMake-cbf0c0fce4dfe23912f7cc012c6f0234a5fd694b.tar.gz
CMake-cbf0c0fce4dfe23912f7cc012c6f0234a5fd694b.tar.bz2
cmake: Enable --warn-uninitialized inside string(CONFIGURE) and configure_file
Fixes: #18489
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommandArgumentParserHelper.cxx6
-rw-r--r--Source/cmMakefile.cxx23
-rw-r--r--Source/cmMakefile.h2
3 files changed, 19 insertions, 12 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
index f94dc24..ca29967 100644
--- a/Source/cmCommandArgumentParserHelper.cxx
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -92,9 +92,11 @@ const char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
return this->AddString(ostr.str());
}
const char* value = this->Makefile->GetDefinition(var);
- if (!value && !this->RemoveEmpty) {
+ if (!value) {
this->Makefile->MaybeWarnUninitialized(var, this->FileName);
- return nullptr;
+ if (!this->RemoveEmpty) {
+ return nullptr;
+ }
}
if (this->EscapeQuotes && value) {
return this->AddString(cmSystemTools::EscapeQuotes(value));
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 256202c..68a5101 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2522,9 +2522,9 @@ const std::string& cmMakefile::ExpandVariablesInString(
// Suppress variable watches to avoid calling hooks twice. Suppress new
// dereferences since the OLD behavior is still what is actually used.
this->SuppressSideEffects = true;
- newError = ExpandVariablesInStringNew(
- newErrorstr, newResult, escapeQuotes, noEscapes, atOnly, filename,
- line, removeEmpty, replaceAt);
+ newError = ExpandVariablesInStringNew(newErrorstr, newResult,
+ escapeQuotes, noEscapes, atOnly,
+ filename, line, replaceAt);
this->SuppressSideEffects = false;
CM_FALLTHROUGH;
}
@@ -2537,9 +2537,9 @@ const std::string& cmMakefile::ExpandVariablesInString(
case cmPolicies::REQUIRED_ALWAYS:
// Messaging here would be *very* verbose.
case cmPolicies::NEW:
- mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
- noEscapes, atOnly, filename, line,
- removeEmpty, replaceAt);
+ mtype =
+ ExpandVariablesInStringNew(errorstr, source, escapeQuotes, noEscapes,
+ atOnly, filename, line, replaceAt);
break;
}
@@ -2726,7 +2726,7 @@ bool cmMakefile::IsProjectFile(const char* filename) const
cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
std::string& errorstr, std::string& source, bool escapeQuotes,
bool noEscapes, bool atOnly, const char* filename, long line,
- bool removeEmpty, bool replaceAt) const
+ bool replaceAt) const
{
// This method replaces ${VAR} and @VAR@ where VAR is looked up
// with GetDefinition(), if not found in the map, nothing is expanded.
@@ -2783,7 +2783,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
} else {
varresult = value;
}
- } else if (!removeEmpty && !this->SuppressSideEffects) {
+ } else if (!this->SuppressSideEffects) {
this->MaybeWarnUninitialized(lookup, filename);
}
result.replace(var.loc, result.size() - var.loc, varresult);
@@ -2896,7 +2896,12 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
if (filename && variable == lineVar) {
varresult = std::to_string(line);
} else {
- varresult = this->GetSafeDefinition(variable);
+ const std::string* def = this->GetDef(variable);
+ if (def) {
+ varresult = *def;
+ } else if (!this->SuppressSideEffects) {
+ this->MaybeWarnUninitialized(variable, filename);
+ }
}
if (escapeQuotes) {
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 1a2a0e7..1607735 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -990,7 +990,7 @@ private:
cmake::MessageType ExpandVariablesInStringNew(
std::string& errorstr, std::string& source, bool escapeQuotes,
bool noEscapes, bool atOnly, const char* filename, long line,
- bool removeEmpty, bool replaceAt) const;
+ bool replaceAt) const;
/**
* Old version of GetSourceFileWithOutput(const std::string&) kept for
* backward-compatibility. It implements a linear search and support