list: Allow inserting at the end of a list

Fixes: #18069
This commit is contained in:
Daniel Chabrowski authored and Brad King committed 2018-07-05 13:53:49 -04:00
1 parent dc70284c81
commit a08154d493
4 files changed
+8 -6

No files matched your search

+2 -4
View File
@@ -289,12 +289,10 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
if (item < 0) {
item = static_cast<int>(nitem) + item;
}
if (item < 0 || nitem <= static_cast<size_t>(item)) {
if (item < 0 || nitem < static_cast<size_t>(item)) {
std::ostringstream str;
str << "index: " << item << " out of range (-" << varArgsExpanded.size()
<< ", "
<< (varArgsExpanded.empty() ? 0 : (varArgsExpanded.size() - 1))
<< ")";
<< ", " << varArgsExpanded.size() << ")";
this->SetError(str.str());
return false;
}
+4
View File
@@ -53,6 +53,10 @@ set(result andy brad)
list(INSERT result -1 bill ken)
TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
set(result andy brad)
list(INSERT result 2 bill ken)
TEST("INSERT result 2 bill ken" "andy;brad;bill;ken")
set(result andy bill brad ken bob)
list(REMOVE_ITEM result bob)
TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
@@ -1,4 +1,4 @@
^CMake Error at INSERT-InvalidIndex.cmake:2 \(list\):
list index: 3 out of range \(-3, 2\)
list index: 4 out of range \(-3, 3\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
@@ -1,2 +1,2 @@
set(mylist alpha bravo charlie)
list(INSERT mylist 3 delta)
list(INSERT mylist 4 delta)