summaryrefslogtreecommitdiffstats
path: root/Source/cmListCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r--Source/cmListCommand.cxx37
1 files changed, 30 insertions, 7 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 42f94b6..1bafdf7 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -34,11 +34,34 @@
namespace {
-bool GetIndexArg(char const* arg, int* idx)
+bool GetIndexArg(char const* arg, int* idx, cmMakefile& mf)
{
long value;
if (!cmStrToLong(arg, &value)) {
- // An error was detected.
+ switch (mf.GetPolicyStatus(cmPolicies::CMP0121)) {
+ case cmPolicies::WARN: {
+ // Default is to warn and use old behavior OLD behavior is to allow
+ // compatibility, so issue a warning and use the previous behavior.
+ std::string warn =
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0121),
+ " Invalid list index \"", arg, "\".");
+ mf.IssueMessage(MessageType::AUTHOR_WARNING, warn);
+ break;
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to allow compatibility, so just ignore the
+ // situation.
+ break;
+ case cmPolicies::NEW:
+ return false;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ std::string msg =
+ cmStrCat(cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0121),
+ " Invalid list index \"", arg, "\".");
+ mf.IssueMessage(MessageType::FATAL_ERROR, msg);
+ break;
+ }
}
// Truncation is happening here, but it had always been happening here.
@@ -166,7 +189,7 @@ bool HandleGetCommand(std::vector<std::string> const& args,
size_t nitem = varArgsExpanded.size();
for (cc = 2; cc < args.size() - 1; cc++) {
int item;
- if (!GetIndexArg(args[cc].c_str(), &item)) {
+ if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
return false;
}
@@ -378,7 +401,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
// expand the variable
int item;
- if (!GetIndexArg(args[2].c_str(), &item)) {
+ if (!GetIndexArg(args[2].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
return false;
}
@@ -1303,11 +1326,11 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
int start;
int length;
- if (!GetIndexArg(args[2].c_str(), &start)) {
+ if (!GetIndexArg(args[2].c_str(), &start, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
return false;
}
- if (!GetIndexArg(args[3].c_str(), &length)) {
+ if (!GetIndexArg(args[3].c_str(), &length, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[3], " is not a valid index"));
return false;
}
@@ -1366,7 +1389,7 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args,
size_t nitem = varArgsExpanded.size();
for (cc = 2; cc < args.size(); ++cc) {
int item;
- if (!GetIndexArg(args[cc].c_str(), &item)) {
+ if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
return false;
}