Fix: Regression in the cmConditionEvaluator::HandleLevel0

As reported in the BUG #22524, mismatched parenthesis reported differently
for `while()` and `if()`.

The problem was in the double loop (over "handlers" and the arguments),
where the outer loop didn't check the result of the running handler.
This commit is contained in:
Alex Turbov
2021-08-09 20:35:56 +03:00
parent 7e3250da2f
commit 61b33c3f4e
7 changed files with 36 additions and 1 deletions

View File

@@ -260,11 +260,17 @@ bool cmConditionEvaluator::IsTrue(
for (auto fn : handlers) {
// Call the reducer 'till there is anything to reduce...
// (i.e., if after an iteration the size becomes smaller)
auto levelResult = true;
for (auto beginSize = newArgs.size();
(this->*fn)(newArgs, errorString, status) &&
(levelResult = (this->*fn)(newArgs, errorString, status)) &&
newArgs.size() < beginSize;
beginSize = newArgs.size()) {
}
if (!levelResult) {
// NOTE `errorString` supposed to be set already
return false;
}
}
// now at the end there should only be one argument left

View File

@@ -9,6 +9,8 @@ run_cmake(duplicate-else-after-elseif)
run_cmake(elseif-message)
run_cmake(misplaced-elseif)
run_cmake(unbalanced-parenthesis)
run_cmake(MatchesSelf)
run_cmake(IncompleteMatches)
run_cmake(IncompleteMatchesFail)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,8 @@
CMake Error at unbalanced-parenthesis\.cmake:[0-9]+ \(if\):
if given arguments:
"NOT" "\(" "IN_LIST" "some_list"
mismatched parenthesis in condition
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,8 @@
set(var_with_paren "(")
set(some_list "")
if(NOT ${var_with_paren} IN_LIST some_list)
message(STATUS "Never prints")
else()
message(STATUS "Never prints")
endif()

View File

@@ -5,3 +5,5 @@ run_cmake(EndMissing)
run_cmake(EndMismatch)
run_cmake(EndAlone)
run_cmake(EndAloneArgs)
run_cmake(unbalanced-parenthesis)

View File

@@ -0,0 +1,8 @@
set(var_with_paren "(")
set(some_list "")
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")