[PATCH] D32574: [libcxx] [test] Fixed possible loss of data warnings in tests on amd64

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 4 03:13:41 PDT 2017


EricWF added inline comments.


================
Comment at: test/std/strings/basic.string/string.cons/T_size_size.pass.cpp:39
         assert(pos <= sv.size());
-        unsigned rlen = std::min<unsigned>(sv.size() - pos, n);
+        unsigned rlen = std::min(static_cast<unsigned>(sv.size()) - pos, n);
         assert(s2.size() == rlen);
----------------
BillyONeal wrote:
> EricWF wrote:
> > The cast should happen after the subtraction, not before.
> The cast happens before the subtraction because the invariant that size() is less than unsigned max is established on line 36 (by passing in an unsigned as the length).
> 
> Alternately, would it be better to just pass around size_ts here so that no casts would be necessary any longer?
> 
Alternately, would it be better to just pass around size_ts here so that no casts would be necessary any longer?

Yeah, that seems more correct to me. Good catch.


https://reviews.llvm.org/D32574





More information about the cfe-commits mailing list