summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-07-06 13:41:18 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-07-06 13:41:24 (GMT)
commit9d1bc0a918d0e3b97a3669e11d0d6ce6710af3b0 (patch)
tree31726647bc30d0eddc2a654c881f5aaa65fd3eb5
parentf6b20179aa21ee6997879d3d0fb3288e79a4b58f (diff)
parenta08154d493a08f1fc1473038f897eb5468a8f79b (diff)
downloadCMake-9d1bc0a918d0e3b97a3669e11d0d6ce6710af3b0.zip
CMake-9d1bc0a918d0e3b97a3669e11d0d6ce6710af3b0.tar.gz
CMake-9d1bc0a918d0e3b97a3669e11d0d6ce6710af3b0.tar.bz2
Merge topic 'list-command-insert'
a08154d493 list: Allow inserting at the end of a list Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2181
-rw-r--r--Source/cmListCommand.cxx6
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in4
-rw-r--r--Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt2
-rw-r--r--Tests/RunCMake/list/INSERT-InvalidIndex.cmake2
4 files changed, 8 insertions, 6 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index ba0c843..d7de2fa 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -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;
}
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
index 76f5e4f..f517e64 100644
--- a/Tests/CMakeTests/ListTest.cmake.in
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -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")
diff --git a/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt b/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
index 6e15c0b..9b9c5e0 100644
--- a/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
+++ b/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
@@ -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\)$
diff --git a/Tests/RunCMake/list/INSERT-InvalidIndex.cmake b/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
index 4103d97..12ac114 100644
--- a/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
+++ b/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
@@ -1,2 +1,2 @@
set(mylist alpha bravo charlie)
-list(INSERT mylist 3 delta)
+list(INSERT mylist 4 delta)