cmListCommand: handle empty lists for list(REMOVE_AT)
Treat an empty list as a list with no valid bounds and return an error message indicating that any given indices are out-of-bounds.
This commit is contained in:
parent
acfe53c588
commit
121a036f73
@ -4,3 +4,6 @@ better-empty-list-behavior
|
||||
* The :command:`list` operations ``REMOVE_ITEM``, ``REMOVE_DUPLICATES``,
|
||||
``SORT``, ``REVERSE``, and ``FILTER`` all now accept a non-existent variable
|
||||
as the list since these operations on empty lists is also the empty list.
|
||||
|
||||
* The :command:`list` operation ``REMOVE_AT`` now indicates that the given
|
||||
indices are invalid for a non-existent variable or empty list.
|
||||
|
@ -1225,13 +1225,17 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args)
|
||||
const std::string& listName = args[1];
|
||||
// expand the variable
|
||||
std::vector<std::string> varArgsExpanded;
|
||||
if (!this->GetList(varArgsExpanded, listName)) {
|
||||
this->SetError("sub-command REMOVE_AT requires list to be present.");
|
||||
return false;
|
||||
if (!this->GetList(varArgsExpanded, listName) || varArgsExpanded.empty()) {
|
||||
std::ostringstream str;
|
||||
str << "index: ";
|
||||
for (size_t i = 1; i < args.size(); ++i) {
|
||||
str << args[i];
|
||||
if (i != args.size() - 1) {
|
||||
str << ", ";
|
||||
}
|
||||
// FIXME: Add policy to make non-existing lists an error like empty lists.
|
||||
if (varArgsExpanded.empty()) {
|
||||
this->SetError("REMOVE_AT given empty list");
|
||||
}
|
||||
str << " out of range (0, 0)";
|
||||
this->SetError(str.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
CMake Error at EmptyRemoveAt0.cmake:2 \(list\):
|
||||
list REMOVE_AT given empty list
|
||||
list index: mylist, 0 out of range \(0, 0\)
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)$
|
||||
|
1
Tests/RunCMake/list/REMOVE_AT-EmptyList-result.txt
Normal file
1
Tests/RunCMake/list/REMOVE_AT-EmptyList-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/list/REMOVE_AT-EmptyList-stderr.txt
Normal file
4
Tests/RunCMake/list/REMOVE_AT-EmptyList-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
^CMake Error at REMOVE_AT-EmptyList.cmake:2 \(list\):
|
||||
list index: nosuchlist, 0 out of range \(0, 0\)
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)$
|
6
Tests/RunCMake/list/REMOVE_AT-EmptyList.cmake
Normal file
6
Tests/RunCMake/list/REMOVE_AT-EmptyList.cmake
Normal file
@ -0,0 +1,6 @@
|
||||
set(nosuchlist "")
|
||||
list(REMOVE_AT nosuchlist 0)
|
||||
if (NOT DEFINED nosuchlist OR NOT nosuchlist STREQUAL "")
|
||||
message(FATAL_ERROR
|
||||
"list(REMOVE_AT) modified our list")
|
||||
endif ()
|
@ -1,4 +1,4 @@
|
||||
^CMake Error at REMOVE_AT-NotList.cmake:2 \(list\):
|
||||
list sub-command REMOVE_AT requires list to be present.
|
||||
list index: nosuchlist, 0 out of range \(0, 0\)
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)$
|
||||
|
@ -1,2 +1,6 @@
|
||||
unset(nosuchlist)
|
||||
list(REMOVE_AT nosuchlist 0)
|
||||
if (DEFINED nosuchlist)
|
||||
message(FATAL_ERROR
|
||||
"list(REMOVE_AT) created our list")
|
||||
endif ()
|
||||
|
@ -22,6 +22,8 @@ run_cmake(REMOVE_DUPLICATES-TooManyArguments)
|
||||
run_cmake(REVERSE-TooManyArguments)
|
||||
run_cmake(SUBLIST-TooManyArguments)
|
||||
|
||||
run_cmake(REMOVE_AT-EmptyList)
|
||||
|
||||
run_cmake(FILTER-NotList)
|
||||
run_cmake(REMOVE_AT-NotList)
|
||||
run_cmake(REMOVE_DUPLICATES-NotList)
|
||||
|
Loading…
Reference in New Issue
Block a user