Fix: while() can silently ignore incorrect condition

When `conditionEvaluator.IsTrue(...)` returns `false` it just
didn't print the error occured.
This commit is contained in:
Alex Turbov
2021-08-09 20:58:27 +03:00
parent 61b33c3f4e
commit 880ca66b51
4 changed files with 25 additions and 19 deletions

View File

@@ -75,24 +75,6 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
conditionEvaluator.IsTrue(expandedArguments, errorString, messageType);
while (isTrue) {
if (!errorString.empty()) {
std::string err = "had incorrect arguments: ";
for (cmListFileArgument const& arg : this->Args) {
err += (arg.Delim ? "\"" : "");
err += arg.Value;
err += (arg.Delim ? "\"" : "");
err += " ";
}
err += "(";
err += errorString;
err += ").";
mf.GetCMakeInstance()->IssueMessage(messageType, err, whileBT);
if (messageType == MessageType::FATAL_ERROR) {
cmSystemTools::SetFatalErrorOccured();
return true;
}
}
// Invoke all the functions that were collected in the block.
for (cmListFileFunction const& fn : functions) {
cmExecutionStatus status(mf);
@@ -116,6 +98,24 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
isTrue =
conditionEvaluator.IsTrue(expandedArguments, errorString, messageType);
}
if (!isTrue && !errorString.empty()) {
std::string err = "had incorrect arguments: ";
for (cmListFileArgument const& arg : this->Args) {
err += (arg.Delim ? "\"" : "");
err += arg.Value;
err += (arg.Delim ? "\"" : "");
err += " ";
}
err += "(";
err += errorString;
err += ").";
mf.GetCMakeInstance()->IssueMessage(messageType, err, whileBT);
if (messageType == MessageType::FATAL_ERROR) {
cmSystemTools::SetFatalErrorOccured();
}
}
return true;
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,5 @@
CMake Error at unbalanced-parenthesis.cmake:[0-9]+ \(while\):
had incorrect arguments: NOT \$\{var_with_paren\} IN_LIST some_list
\(mismatched parenthesis in condition\).
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)

View File

@@ -5,4 +5,4 @@ while(NOT ${var_with_paren} IN_LIST some_list)
message(STATUS "Never prints")
endwhile()
message(STATUS "It prints but in fact `while()` have to fail")
message(STATUS "Never prints")