foreach: Set fatal error on invalid range

Fixes: #20394
This commit is contained in:
Kyle Edwards
2020-02-27 13:54:42 -05:00
parent a33b3949e5
commit 185d1aefaa
5 changed files with 9 additions and 0 deletions

View File

@@ -428,6 +428,7 @@ bool cmForEachCommand(std::vector<std::string> const& args,
status.SetError(
cmStrCat("called with incorrect range specification: start ", start,
", stop ", stop, ", step ", step));
cmSystemTools::SetFatalErrorOccured();
return false;
}

View File

@@ -18,3 +18,4 @@ run_cmake(foreach-RANGE-non-int-test-2-2)
run_cmake(foreach-RANGE-non-int-test-3-1)
run_cmake(foreach-RANGE-non-int-test-3-2)
run_cmake(foreach-RANGE-non-int-test-3-3)
run_cmake(foreach-RANGE-invalid-test)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at foreach-RANGE-invalid-test\.cmake:[0-9]+ \(foreach\):
foreach called with incorrect range specification: start 2, stop 1, step 1
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)$

View File

@@ -0,0 +1,2 @@
foreach(a RANGE 2 1 1)
endforeach()