Merge topic 'if-invalid'

240481490c if: Diagnose invalid argument in parentheses

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12114
This commit is contained in:
Brad King
2026-05-28 13:56:29 +00:00
committed by Kitware Robot
9 changed files with 34 additions and 0 deletions

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

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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()

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

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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")

View File

@@ -1,6 +1,7 @@
include(RunCMake)
run_cmake(MissingArgument)
run_cmake(InvalidArgument)
run_cmake(EndMissing)
run_cmake(EndMismatch)
run_cmake(EndAlone)