fix some of the warning/errors clang 3.1 reports
authorPhilip Pronin <philipp@fb.com>
Mon, 14 Jan 2013 23:03:00 +0000 (15:03 -0800)
committerJordan DeLong <jdelong@fb.com>
Sat, 19 Jan 2013 00:38:09 +0000 (16:38 -0800)
Summary: One step closer to build folly with clang

Test Plan:
fbconfig -r folly && fbmake opt -j32

to make sure gcc is still able to compile it

Reviewed By: tudorb@fb.com

FB internal diff: D677716

folly/Benchmark.h
folly/Format-inl.h
folly/Padded.h
folly/Subprocess.cpp
folly/experimental/Gen-inl.h
folly/test/FormatTest.cpp
folly/test/TimeseriesTest.cpp

index 2b68c4fae501a760c6e07d8b75513f876a8921c3..5e155f2851f3b726ecf246411e3e75a232abce71 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -185,7 +185,7 @@ typename std::enable_if<
   == 2
 >::type
 addBenchmark(const char* file, const char* name, Lambda&& lambda) {
-  auto execute = [=](unsigned int times) {
+  auto execute = [=](unsigned int times) -> uint64_t {
     BenchmarkSuspender::nsSpent = 0;
     timespec start, end;
 
index 944e2869ad68ccd0975a01c4a7b55e69e4a0ff9b..bba7be85ed588e310412f70054f7e1c407c3dfb0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,7 +43,9 @@ const size_t kMaxBinaryLength = 8 * sizeof(uintmax_t);
 template <class Uint>
 size_t uintToHex(char* buffer, size_t bufLen, Uint v,
                  const char (&repr)[256][2]) {
-  for (; v >= 256; v >>= 8) {
+  // 'v >>= 7, v >>= 1' is no more than a work around to get rid of shift size
+  // warning when Uint = uint8_t (it's false as v >= 256 implies sizeof(v) > 1).
+  for (; v >= 256; v >>= 7, v >>= 1) {
     auto b = v & 0xff;
     bufLen -= 2;
     buffer[bufLen] = repr[b][0];
@@ -85,7 +87,9 @@ inline size_t uintToHexUpper(char* buffer, size_t bufLen, Uint v) {
 template <class Uint>
 size_t uintToOctal(char* buffer, size_t bufLen, Uint v) {
   auto& repr = formatOctal;
-  for (; v >= 512; v >>= 9) {
+  // 'v >>= 7, v >>= 2' is no more than a work around to get rid of shift size
+  // warning when Uint = uint8_t (it's false as v >= 512 implies sizeof(v) > 1).
+  for (; v >= 512; v >>= 7, v >>= 2) {
     auto b = v & 0x1ff;
     bufLen -= 3;
     buffer[bufLen] = repr[b][0];
@@ -117,7 +121,7 @@ size_t uintToBinary(char* buffer, size_t bufLen, Uint v) {
     buffer[--bufLen] = '0';
     return bufLen;
   }
-  for (; v; v >>= 8) {
+  for (; v; v >>= 7, v >>= 1) {
     auto b = v & 0xff;
     bufLen -= 8;
     memcpy(buffer + bufLen, &(repr[b][0]), 8);
index 4c0af2afbf64edcc5020fd379dccdbe2091f6f25..f4d3b9c7af57d72deb2f644d015bf2e4fbb61ccf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 
 #include <cassert>
 #include <cstdint>
+#include <cstring>
 #include <functional>
 #include <iterator>
 #include <limits>
index e8963dc8950045dbc9bc6c3330a1d67f062f4763..da69e5368e4649f1da07317e9b432077b9b6ffdb 100644 (file)
@@ -442,12 +442,6 @@ void Subprocess::sendSignal(int signal) {
 }
 
 namespace {
-void setNonBlocking(int fd) {
-  int flags = ::fcntl(fd, F_GETFL);
-  checkUnixError(flags, "fcntl");
-  int r = ::fcntl(fd, F_SETFL, flags | O_NONBLOCK);
-  checkUnixError(r, "fcntl");
-}
 
 std::pair<const uint8_t*, size_t> queueFront(const IOBufQueue& queue) {
   auto* p = queue.front();
@@ -544,7 +538,7 @@ std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf(
     IOBufQueue data) {
   std::pair<IOBufQueue, IOBufQueue> out;
 
-  auto readCallback = [&] (int pfd, int cfd) {
+  auto readCallback = [&] (int pfd, int cfd) -> bool {
     if (cfd == 1 && flags.readStdout_) {
       return handleRead(pfd, out.first);
     } else if (cfd == 2 && flags.readStderr_) {
@@ -556,7 +550,7 @@ std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf(
     }
   };
 
-  auto writeCallback = [&] (int pfd, int cfd) {
+  auto writeCallback = [&] (int pfd, int cfd) -> bool {
     if (cfd == 0 && flags.writeStdin_) {
       return handleWrite(pfd, data);
     } else {
index 6473b25435425ee6f33fb54d665370f710469790..bde69792c7b9f151c99ed1191661af7ef572c922 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -175,7 +175,7 @@ class GenImpl : public FBounded<Self> {
    */
   template<class Body>
   void foreach(Body&& body) const {
-    this->self().apply([&](Value value) {
+    this->self().apply([&](Value value) -> bool {
         body(std::forward<Value>(value));
         return true;
       });
@@ -664,7 +664,7 @@ class Until : public Operator<Until<Predicate>> {
       public GenImpl<Result, Generator<Value, Source, Result>> {
     Source source_;
     Predicate pred_;
-  public:
+   public:
     explicit Generator(Source source, const Predicate& pred)
       : source_(std::move(source)), pred_(pred) {}
 
@@ -703,7 +703,7 @@ class Until : public Operator<Until<Predicate>> {
  */
 class Take : public Operator<Take> {
   size_t count_;
-public:
+ public:
   explicit Take(size_t count)
     : count_(count) {}
 
@@ -756,7 +756,7 @@ public:
  */
 class Skip : public Operator<Skip> {
   size_t count_;
-public:
+ public:
   explicit Skip(size_t count)
     : count_(count) {}
 
@@ -766,7 +766,7 @@ public:
       public GenImpl<Value, Generator<Value, Source>> {
     Source source_;
     size_t count_;
-  public:
+   public:
     explicit Generator(Source source, size_t count)
       : source_(std::move(source)) , count_(count) {}
 
@@ -835,8 +835,8 @@ class Order : public Operator<Order<Selector, Comparer>> {
   Selector selector_;
   Comparer comparer_;
  public:
-  Order(const Selector& selector = Selector(),
-        const Comparer& comparer = Comparer())
+  explicit Order(const Selector& selector = Selector(),
+                 const Comparer& comparer = Comparer())
     : selector_(selector) , comparer_(comparer) {}
 
   template<class Value,
@@ -933,11 +933,11 @@ template<class First,
 class Composed : public Operator<Composed<First, Second>> {
   First first_;
   Second second_;
 public:
-    Composed() {}
-    Composed(First first, Second second)
-      : first_(std::move(first))
-      , second_(std::move(second)) {}
+ public:
+  Composed() {}
+  Composed(First first, Second second)
+    : first_(std::move(first))
+    , second_(std::move(second)) {}
 
   template<class Source,
            class Value,
@@ -1007,6 +1007,8 @@ class FoldLeft : public Operator<FoldLeft<Seed, Fold>> {
  */
 class First : public Operator<First> {
  public:
+  First() { }
+
   template<class Source,
            class Value,
            class StorageType = typename std::decay<Value>::type>
@@ -1033,6 +1035,8 @@ class First : public Operator<First> {
  */
 class Any : public Operator<Any> {
  public:
+  Any() { }
+
   template<class Source,
            class Value>
   bool compose(const GenImpl<Value, Source>& source) const {
@@ -1061,7 +1065,7 @@ template<class Reducer>
 class Reduce : public Operator<Reduce<Reducer>> {
   Reducer reducer_;
  public:
-  Reduce(const Reducer& reducer)
+  explicit Reduce(const Reducer& reducer)
     : reducer_(reducer)
   {}
 
@@ -1093,6 +1097,8 @@ class Reduce : public Operator<Reduce<Reducer>> {
  */
 class Count : public Operator<Count> {
  public:
+  Count() { }
+
   template<class Source,
            class Value>
   size_t compose(const GenImpl<Value, Source>& source) const {
@@ -1112,6 +1118,8 @@ class Count : public Operator<Count> {
  */
 class Sum : public Operator<Sum> {
  public:
+  Sum() { }
+
   template<class Source,
            class Value,
            class StorageType = typename std::decay<Value>::type>
@@ -1141,8 +1149,8 @@ class Min : public Operator<Min<Selector, Comparer>> {
   Selector selector_;
   Comparer comparer_;
  public:
-  Min(const Selector& selector = Selector(),
-      const Comparer& comparer = Comparer())
+  explicit Min(const Selector& selector = Selector(),
+               const Comparer& comparer = Comparer())
     : selector_(selector)
     , comparer_(comparer)
   {}
@@ -1211,6 +1219,8 @@ class Append : public Operator<Append<Collection>> {
 template<class Collection>
 class Collect : public Operator<Collect<Collection>> {
  public:
+  Collect() { }
+
   template<class Value,
            class Source,
            class StorageType = typename std::decay<Value>::type>
@@ -1243,6 +1253,8 @@ template<template<class, class> class Container,
          template<class> class Allocator>
 class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
  public:
+  CollectTemplate() { }
+
   template<class Value,
            class Source,
            class StorageType = typename std::decay<Value>::type,
@@ -1255,6 +1267,7 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
     return collection;
   }
 };
+
 /**
  * Concat - For flattening generators of generators.
  *
@@ -1272,14 +1285,16 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
  *     | as<std::set>();
  */
 class Concat : public Operator<Concat> {
-public:
+ public:
+  Concat() { }
+
   template<class Inner,
            class Source,
            class InnerValue = typename std::decay<Inner>::type::ValueType>
   class Generator :
       public GenImpl<InnerValue, Generator<Inner, Source, InnerValue>> {
     Source source_;
-  public:
+   public:
     explicit Generator(Source source)
       : source_(std::move(source)) {}
 
@@ -1326,7 +1341,9 @@ public:
  *     | as<std::set>();
  */
 class RangeConcat : public Operator<RangeConcat> {
-public:
+ public:
+  RangeConcat() { }
+
   template<class Source,
            class Range,
            class InnerValue = typename ValueTypeOfRange<Range>::RefType>
@@ -1348,7 +1365,7 @@ public:
 
     template<class Handler>
     bool apply(Handler&& handler) const {
-      return source_.apply([&](Range range) {
+      return source_.apply([&](Range range) -> bool {
           for (auto& value : range) {
             if (!handler(value)) {
               return false;
index c34fd49c0f8560196223b798efe095535625ad18..96de6bf68cafa7f7bd1ea6430a10d15c3ea061e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -186,15 +186,6 @@ TEST(Format, Simple) {
   EXPECT_EQ("42 23 hello worldXX", s);
 }
 
-namespace {
-void testFloat(const char* fmt, double val) {
-  char buf[100];
-  sprintf(buf, to<std::string>("%", fmt).c_str(), val);
-
-  EXPECT_EQ(buf, fstr(to<std::string>("{:", fmt, "}"), val));
-}
-}  // namespace
-
 TEST(Format, Float) {
   double d = 1;
   EXPECT_EQ("1", fstr("{}", 1.0));
index 69dbe9ad64a2b2448f1839d5542f59bad63e641a..7972eda78cbdd9952d672af945942670eb277216 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include "folly/stats/BucketedTimeSeries.h"
 #include "folly/stats/BucketedTimeSeries-defs.h"
 
@@ -475,7 +476,7 @@ TEST(BucketedTimeSeries, forEachBucket) {
 
     vector<BucketInfo> info;
     auto fn = [&](const Bucket& bucket, seconds bucketStart,
-                  seconds bucketEnd) {
+                  seconds bucketEnd) -> bool {
       info.emplace_back(&bucket, bucketStart, bucketEnd);
       return true;
     };