mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 03:39:43 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
1
Tests/RunCMake/if/unbalanced-parenthesis-result.txt
Normal file
1
Tests/RunCMake/if/unbalanced-parenthesis-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
8
Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt
Normal file
8
Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt
Normal 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\)
|
||||
8
Tests/RunCMake/if/unbalanced-parenthesis.cmake
Normal file
8
Tests/RunCMake/if/unbalanced-parenthesis.cmake
Normal 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()
|
||||
@@ -5,3 +5,5 @@ run_cmake(EndMissing)
|
||||
run_cmake(EndMismatch)
|
||||
run_cmake(EndAlone)
|
||||
run_cmake(EndAloneArgs)
|
||||
|
||||
run_cmake(unbalanced-parenthesis)
|
||||
|
||||
8
Tests/RunCMake/while/unbalanced-parenthesis.cmake
Normal file
8
Tests/RunCMake/while/unbalanced-parenthesis.cmake
Normal 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")
|
||||
Reference in New Issue
Block a user