Fix some clang compiler warnings/errors
authorGaurav Jain <gjain@fb.com>
Thu, 6 Dec 2012 19:26:17 +0000 (11:26 -0800)
committerJordan DeLong <jdelong@fb.com>
Sun, 16 Dec 2012 22:49:32 +0000 (14:49 -0800)
Summary:
Fixes instances of the following problems:
error: offset of on non-POD type 'folly::fbstring_core<char>::RefCounted'
[-Werror,-Winvalid-offsetof]
Solution: Since the atomic is not a POD I used sizeof() instead to calculate
the offset

warning: C++11 requires lambda with omitted result type to consist of a single
return statement
Solution: Specify a return type

error: in-class initializer for static data member is not a constant expression
Solution: Move initializer

Test Plan: - Compiled folly and ran fbmake runtests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D656963

folly/FBString.h
folly/Range.h
folly/Traits.h
folly/json.cpp
folly/small_vector.h
folly/stats/BucketedTimeSeries-defs.h

index 11ec56022146a790227a0766388bcc55d3f1ea61..bf8a9807c3a2fe3ce507cd0db1068a3317d0ecf7 100644 (file)
@@ -729,7 +729,7 @@ private:
       return static_cast<RefCounted*>(
         static_cast<void*>(
           static_cast<unsigned char*>(static_cast<void*>(p))
-          - offsetof(RefCounted, data_)));
+          - sizeof(refCount_)));
     }
 
     static size_t refs(Char * p) {
index ae4310f49eb906764d22c124a2df0a532e0228bf..2264d2533df29e3617a8ba7ff86a609f38bfb167 100644 (file)
@@ -120,7 +120,7 @@ public:
   typedef typename std::iterator_traits<Iter>::reference reference;
   typedef std::char_traits<value_type> traits_type;
 
-  static const size_type npos = std::string::npos;
+  static const size_type npos;
 
   // Works for all iterators
   Range() : b_(), e_() {
@@ -423,7 +423,7 @@ private:
 };
 
 template <class Iter>
-const typename Range<Iter>::size_type Range<Iter>::npos;
+const typename Range<Iter>::size_type Range<Iter>::npos = std::string::npos;
 
 template <class T>
 void swap(Range<T>& lhs, Range<T>& rhs) {
index f2a517f203cf816e5f174f513e467fbe85a06c6d..7432dec5c2ed95645cfcf9f71100ff73dd745aed 100644 (file)
@@ -225,7 +225,7 @@ template <class T> struct IsZeroInitializable
 namespace std {
 
 template <class T, class U>
-  class pair;
+  struct pair;
 #ifndef _GLIBCXX_USE_FB
 template <class T, class R, class A>
   class basic_string;
index 0d9996ac5ff313c7ab43ef599f86b854f6e87246..710f3b03eacd747cd08f76c85459b4acaec1dbd5 100644 (file)
@@ -542,7 +542,7 @@ fbstring decodeUnicodeEscape(Input& in) {
            (in.error("invalid hex digit"), 0);
   };
 
-  auto readHex = [&] {
+  auto readHex = [&]() -> uint16_t {
     if (in.size() < 4) {
       in.error("expected 4 hex digits");
     }
index 4a0fa276f3ab1a469582447bdb8b3b054aaaa9fa..911f0630fc936439c31bfffbcf96c264aef9b649 100644 (file)
@@ -100,7 +100,7 @@ struct OneBitMutex;
 //////////////////////////////////////////////////////////////////////
 
 template<class T, std::size_t M, class A, class B, class C>
-struct small_vector;
+class small_vector;
 
 //////////////////////////////////////////////////////////////////////
 
index 61bf7f613bbc46a5e2c2fe6931cd18c106f3b4f0..28ada12d2c51c216561aba960aae0c0bde6b6515 100644 (file)
@@ -191,7 +191,7 @@ VT BucketedTimeSeries<VT, TT>::sum(TimeType start, TimeType end) const {
   ValueType sum = ValueType();
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
-                                TimeType nextBucketStart) {
+                                TimeType nextBucketStart) -> bool {
     sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                              bucket.sum);
     return true;
@@ -205,7 +205,7 @@ uint64_t BucketedTimeSeries<VT, TT>::count(TimeType start, TimeType end) const {
   uint64_t count = 0;
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
-                                TimeType nextBucketStart) {
+                                TimeType nextBucketStart) -> bool {
     count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                                bucket.count);
     return true;
@@ -221,7 +221,7 @@ ReturnType BucketedTimeSeries<VT, TT>::avg(TimeType start, TimeType end) const {
   uint64_t count = 0;
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
-                                TimeType nextBucketStart) {
+                                TimeType nextBucketStart) -> bool {
     sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                              bucket.sum);
     count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
@@ -396,7 +396,7 @@ template <typename Function>
 void BucketedTimeSeries<VT, TT>::forEachBucket(TimeType start, TimeType end,
                                                Function fn) const {
   forEachBucket([&start, &end, &fn] (const Bucket& bucket, TimeType bucketStart,
-                                     TimeType nextBucketStart) {
+                                     TimeType nextBucketStart) -> bool {
     if (start >= nextBucketStart) {
       return true;
     }