if: Diagnose invalid argument in parentheses

Fixes: #26424
This commit is contained in:
Ruslan Baratov
2026-05-27 12:24:32 -04:00
committed by Brad King
parent 3d9d779232
commit 240481490c
9 changed files with 34 additions and 0 deletions
+3
View File
@@ -409,6 +409,9 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
// now recursively invoke IsTrue to handle the values inside the
// parenthetical expression
auto const value = this->IsTrue(subExpr, errorString, status);
if (!errorString.empty()) {
return false;
}
*arg = cmExpandedCommandArgument(bool2string(value), true);
argOpen = std::next(arg);
// remove the now evaluated parenthetical expression
@@ -0,0 +1 @@
1
@@ -0,0 +1,8 @@
^CMake Error at InvalidArgumentInParenthesis\.cmake:1 \(if\):
if given arguments:
"\(" "A" "B" "\)" "OR" "\(" "" "\)"
Unknown arguments specified
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)$
@@ -0,0 +1,5 @@
if((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}"))
message(STATUS "Invalid evaluated to TRUE")
else()
message(STATUS "Invalid evaluated to FALSE")
endif()
+1
View File
@@ -1,6 +1,7 @@
include(RunCMake)
run_cmake(InvalidArgument1)
run_cmake(InvalidArgumentInParenthesis)
run_cmake(exists)
if(NOT MSYS)
# permissions and symbolic links are broken on MSYS
@@ -0,0 +1 @@
1
@@ -0,0 +1,8 @@
^CMake Error at InvalidArgument\.cmake:2 \(while\):
while\(\) given incorrect arguments:
"\(" "A" "B" "\)" "OR" "\(" "" "\)"
Unknown arguments specified
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)$
@@ -0,0 +1,6 @@
cmake_policy(SET CMP0130 NEW)
while((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}"))
message(STATUS "Invalid evaluated to TRUE")
return()
endwhile()
message(STATUS "Invalid evaluated to FALSE")
+1
View File
@@ -1,6 +1,7 @@
include(RunCMake)
run_cmake(MissingArgument)
run_cmake(InvalidArgument)
run_cmake(EndMissing)
run_cmake(EndMismatch)
run_cmake(EndAlone)