Repository: dtolnay/cxx (language: rust)

Issue:
MSVC warning C4365: signed/unsigned mismatch in cxx.cc operator<< overloads
After a recent compiler upgrade on Windows, I started seeing a warning that there's a signed/unsigned mismatch in `cxx.cc`:

```cpp
std::ostream &operator<<(std::ostream &os, const String &s) {
  os.write(s.data(), s.size());
  return os;
}
```

The `s.size()` method returns `std::size_t`, but `os.write` takes a signed [`std::streamsize`](https://en.cppreference.com/w/cpp/io/streamsize)

I think the same probably applies to the equivalent `Str` operator below that, but in my case the warning was treated as an error, and it seems to have stopped compilation rather than reporting that one.


Discussion / hints:

Fix patch:
diff --git a/src/cxx.cc b/src/cxx.cc
index 4958eb08b..4aac64279 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -285,7 +285,7 @@ String::String(unsafe_bitcopy_t, const String &bits) noexcept
     : repr(bits.repr) {}
 
 std::ostream &operator<<(std::ostream &os, const String &s) {
-  os.write(s.data(), s.size());
+  os.write(s.data(), static_cast<std::streamsize>(s.size()));
   return os;
 }
 
@@ -374,7 +374,7 @@ void Str::swap(Str &rhs) noexcept {
 }
 
 std::ostream &operator<<(std::ostream &os, const Str &s) {
-  os.write(s.data(), s.size());
+  os.write(s.data(), static_cast<std::streamsize>(s.size()));
   return os;
 }
 


Test patch: