From 7b3464320f24167d09592fe05b04ea9b6677fd9d Mon Sep 17 00:00:00 2001
From: Matthew Woehlke <matthew.woehlke@kitware.com>
Date: Tue, 29 Aug 2023 15:57:24 -0400
Subject: [PATCH] Reduce sign conversion warnings

Add some static casts to make explicit some sign conversions in order to
avoid warnings about the same. This is by no means an attempt to fix all
such warnings, but these instances were especially egregious as they
would be raised across many source files.

Also change a post-increment of an iterator to pre-increment. At worst,
this does nothing, but pre-increment is potentially more efficient.
---
 Source/cmList.h     | 10 ++++++----
 Source/cmString.hxx |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/Source/cmList.h b/Source/cmList.h
index 0f875e716e..1b94c2f2e0 100644
--- a/Source/cmList.h
+++ b/Source/cmList.h
@@ -747,8 +747,10 @@ public:
                        ExpandElements expandElements = ExpandElements::Yes,
                        EmptyElements emptyElements = EmptyElements::No)
   {
-    this->insert(this->begin() + this->ComputeInsertIndex(index), first, last,
-                 expandElements, emptyElements);
+    auto const offset =
+      static_cast<difference_type>(this->ComputeInsertIndex(index));
+    this->insert(this->begin() + offset, first, last, expandElements,
+                 emptyElements);
     return *this;
   }
   template <typename InputIterator>
@@ -1186,13 +1188,13 @@ private:
         auto size = container.size();
         insertPos = cmList::Insert(container, insertPos, *first,
                                    expandElements, emptyElements);
-        insertPos += container.size() - size;
+        insertPos += static_cast<decltype(delta)>(container.size() - size);
       }
     } else {
       for (; first != last; ++first) {
         if (!first->empty() || emptyElements == EmptyElements::Yes) {
           insertPos = container.insert(insertPos, *first);
-          insertPos++;
+          ++insertPos;
         }
       }
     }
diff --git a/Source/cmString.hxx b/Source/cmString.hxx
index 86b21c8ef7..1994c2ce10 100644
--- a/Source/cmString.hxx
+++ b/Source/cmString.hxx
@@ -493,8 +493,8 @@ public:
                   char ch)
   {
     std::string out;
-    out.reserve((first - this->view_.begin()) + count2 +
-                (this->view_.end() - last));
+    out.reserve(static_cast<size_type>(first - this->view_.begin()) + count2 +
+                static_cast<size_type>(this->view_.end() - last));
     out.append(this->view_.begin(), first);
     out.append(count2, ch);
     out.append(last, this->view_.end());
-- 
GitLab