folly/FBVector.h: avoid -Wsign-compare error (simple)
authorJim Meyering <meyering@fb.com>
Wed, 7 Jan 2015 01:21:42 +0000 (17:21 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:04 +0000 (11:01 -0800)
Summary:
* folly/FBVector.h (make_window): Declare "tail" to be
explicitly of the same type as "n".  Otherwise, we'd
use the type of std::distance, which is unsigned, and
then compare that against "n" of type "size_type", which
is unsigned, and we'd get this from gcc-4.9:
folly/FBVector.h:1276:14: 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: philipp@fb.com, andrei.alexandrescu@fb.com

Subscribers: trunkagent, njormrod, folly-diffs@

FB internal diff: D1768346

Tasks: 5941250

Signature: t1:1768346:1420594452:654dac805bb46f7c6a38b4e4102e4004720d6835

folly/FBVector.h

index 6abc45294414fb18e2eb4d157d5738c34c80073c..d6cd6937cc67fe2757337db317d2d25d80b1361a 100644 (file)
@@ -1271,7 +1271,8 @@ private: // we have the private section first because it defines some macros
     assert(size() + n <= capacity());
     assert(n != 0);
 
-    auto tail = std::distance(position, impl_.e_);
+    // The result is guaranteed to be non-negative, so use an unsigned type:
+    size_type tail = std::distance(position, impl_.e_);
 
     if (tail <= n) {
       relocate_move(position + n, position, impl_.e_);