From: Jim Meyering Date: Tue, 6 Jan 2015 23:32:33 +0000 (-0800) Subject: folly/small_vector.h: avoid -Wsign-compare error X-Git-Tag: v0.22.0~35 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=67a4edadf17fc386d11fc26c5c47d0da12c0be48;p=folly.git folly/small_vector.h: avoid -Wsign-compare error Summary: * folly/small_vector.h (moveToUninitialized): Do not mix signed and unsigned for-loop index/limit. Instead, eliminate the intermediate "count" altogether and iterate as long as "first" is not equal to "last". Otherwise, gcc-4.9 fails with e.g., folly/small_vector.h:115:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] Test Plan: Run this and note there are fewer errors than before: fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo Reviewed By: soren@fb.com Subscribers: trunkagent, folly-diffs@ FB internal diff: D1767844 Tasks: 5941250 Signature: t1:1767844:1420601608:987fd7f7d44197ed9919910c9b559b37fbe421b6 --- diff --git a/folly/small_vector.h b/folly/small_vector.h index 132ff241..b03eec05 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -109,10 +109,9 @@ namespace detail { !FOLLY_IS_TRIVIALLY_COPYABLE(T) >::type moveToUninitialized(T* first, T* last, T* out) { - auto const count = last - first; std::size_t idx = 0; try { - for (; idx < count; ++first, ++idx) { + for (; first != last; ++first, ++idx) { new (&out[idx]) T(std::move(*first)); } } catch (...) {