Skip to content

Commit 2404814

Browse files
ruslobradking
authored andcommitted
if: Diagnose invalid argument in parentheses
Fixes: #26424
1 parent 3d9d779 commit 2404814

9 files changed

Lines changed: 34 additions & 0 deletions

Source/cmConditionEvaluator.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
409409
// now recursively invoke IsTrue to handle the values inside the
410410
// parenthetical expression
411411
auto const value = this->IsTrue(subExpr, errorString, status);
412+
if (!errorString.empty()) {
413+
return false;
414+
}
412415
*arg = cmExpandedCommandArgument(bool2string(value), true);
413416
argOpen = std::next(arg);
414417
// remove the now evaluated parenthetical expression
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
^CMake Error at InvalidArgumentInParenthesis\.cmake:1 \(if\):
2+
if given arguments:
3+
4+
"\(" "A" "B" "\)" "OR" "\(" "" "\)"
5+
6+
Unknown arguments specified
7+
Call Stack \(most recent call first\):
8+
CMakeLists\.txt:3 \(include\)$
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}"))
2+
message(STATUS "Invalid evaluated to TRUE")
3+
else()
4+
message(STATUS "Invalid evaluated to FALSE")
5+
endif()

Tests/RunCMake/if/RunCMakeTest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include(RunCMake)
22

33
run_cmake(InvalidArgument1)
4+
run_cmake(InvalidArgumentInParenthesis)
45
run_cmake(exists)
56
if(NOT MSYS)
67
# permissions and symbolic links are broken on MSYS
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
^CMake Error at InvalidArgument\.cmake:2 \(while\):
2+
while\(\) given incorrect arguments:
3+
4+
"\(" "A" "B" "\)" "OR" "\(" "" "\)"
5+
6+
Unknown arguments specified
7+
Call Stack \(most recent call first\):
8+
CMakeLists\.txt:3 \(include\)$
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_policy(SET CMP0130 NEW)
2+
while((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}"))
3+
message(STATUS "Invalid evaluated to TRUE")
4+
return()
5+
endwhile()
6+
message(STATUS "Invalid evaluated to FALSE")

Tests/RunCMake/while/RunCMakeTest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include(RunCMake)
22

33
run_cmake(MissingArgument)
4+
run_cmake(InvalidArgument)
45
run_cmake(EndMissing)
56
run_cmake(EndMismatch)
67
run_cmake(EndAlone)

0 commit comments

Comments
 (0)