cmake/0010-list-restore-SUBLIST-behavior.patch

87 lines
2.3 KiB
Diff

From 1cfaed0684e7e26687a3a0a607925456dc656c57 Mon Sep 17 00:00:00 2001
From: Marc Chevrier <marc.chevrier@gmail.com>
Date: Fri, 16 Jun 2023 15:09:57 +0200
Subject: [PATCH] list(): restore SUBLIST behavior
Fixes: #25002
---
Source/cmList.h | 2 +-
Tests/RunCMake/list/SUBLIST.cmake | 51 +++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/Source/cmList.h b/Source/cmList.h
index d9ce9510c6b..eba0400c934 100644
--- a/Source/cmList.h
+++ b/Source/cmList.h
@@ -322,7 +322,7 @@ public:
// extract sublist in range [first, last)
cmList sublist(const_iterator first, const_iterator last) const
{
- return cmList{ first, last };
+ return cmList{ first, last, ExpandElements::No, EmptyElements::Yes };
}
// Extract sublist in range [first, last)
// Throw std::out_of_range if pos is invalid
diff --git a/Tests/RunCMake/list/SUBLIST.cmake b/Tests/RunCMake/list/SUBLIST.cmake
index fd15c28447d..6a33addc846 100644
--- a/Tests/RunCMake/list/SUBLIST.cmake
+++ b/Tests/RunCMake/list/SUBLIST.cmake
@@ -44,3 +44,54 @@ list(SUBLIST mylist 1 -1 result)
if (NOT result STREQUAL "bravo;charlie;delta")
message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \"bravo;charlie;delta\"")
endif()
+
+
+set(mylist ";;")
+
+unset(result)
+list(SUBLIST mylist 0 0 result)
+
+if (NOT result STREQUAL "")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \"\"")
+endif()
+
+unset(result)
+list(SUBLIST mylist 0 1 result)
+
+if (NOT result STREQUAL "")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \"\"")
+endif()
+
+unset(result)
+list(SUBLIST mylist 0 2 result)
+
+if (NOT result STREQUAL ";")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \";\"")
+endif()
+
+unset(result)
+list(SUBLIST mylist 0 3 result)
+
+if (NOT result STREQUAL ";;")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \";;\"")
+endif()
+
+
+set(mylist [[a\;b;c\;d;e]])
+
+unset(result)
+list(SUBLIST mylist 1 2 result)
+
+if (NOT result STREQUAL "c;d;e")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \"c;d;e\"")
+endif()
+
+
+set(mylist [[a\;b;c\\;d;e;f;g;h]])
+
+unset(result)
+list(SUBLIST mylist 1 -1 result)
+
+if (NOT result STREQUAL "c\\;d;e;f;g;h")
+ message (FATAL_ERROR "SUBLIST is \"${result}\", expected is \"c\\;d;e;f;g;h\"")
+endif()
--
GitLab