Repository: dtolnay/cxx (language: rust)

Issue:
MSVC warning C4365: signed/unsigned mismatch in cxx.h iterator operator- overload
This is very similar to #1225, but I missed this one in `cxx.h` because it happened later in my own code once building the `cxx` crate dependency was unblocked:

```cpp
template <typename T>
typename Slice<T>::iterator::difference_type
Slice<T>::iterator::operator-(const iterator &other) const noexcept {
  auto diff = std::distance(static_cast<char *>(other.pos),
                            static_cast<char *>(this->pos));
  return diff / this->stride;
}
```

It's reporting the same signed/unsigned warning (treated as an error in my case), but this time the issue is that `this->stride` is a `size_t` and `diff` and the `typename Slice<T>::iterator::difference_type` return type are both signed `ptrdiff_t`.

I should have a fix, but I want to make sure there aren't any more of these lurking in my code before I make another PR.


Discussion / hints:

Fix patch:
diff --git a/include/cxx.h b/include/cxx.h
index 907ee829f..5d3b694ca 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -659,7 +659,7 @@ typename Slice<T>::iterator::difference_type
 Slice<T>::iterator::operator-(const iterator &other) const noexcept {
   auto diff = std::distance(static_cast<char *>(other.pos),
                             static_cast<char *>(this->pos));
-  return diff / this->stride;
+  return diff / static_cast<typename Slice<T>::iterator::difference_type>(this->stride);
 }
 
 template <typename T>


Test patch: