From 67a4edadf17fc386d11fc26c5c47d0da12c0be48 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 6 Jan 2015 15:32:33 -0800 Subject: [PATCH] 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 --- folly/small_vector.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 (...) { -- 2.34.1