Fixes: #20394
@@ -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;
}
@@ -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)
@@ -0,0 +1 @@
+1
@@ -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\)$
@@ -0,0 +1,2 @@
+foreach(a RANGE 2 1 1)
+endforeach()