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

Billy Robert O'Neal III via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 4 02:41:43 PDT 2017

BillyONeal 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);
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?


More information about the cfe-commits mailing list