From 83da0042ba4f4c6622bde2002a0bd968de1ed701 Mon Sep 17 00:00:00 2001 From: Gaurav Jain Date: Thu, 6 Dec 2012 11:26:17 -0800 Subject: [PATCH] Fix some clang compiler warnings/errors Summary: Fixes instances of the following problems: error: offset of on non-POD type 'folly::fbstring_core::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 | 2 +- folly/Range.h | 4 ++-- folly/Traits.h | 2 +- folly/json.cpp | 2 +- folly/small_vector.h | 2 +- folly/stats/BucketedTimeSeries-defs.h | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index 11ec5602..bf8a9807 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -729,7 +729,7 @@ private: return static_cast( static_cast( static_cast(static_cast(p)) - - offsetof(RefCounted, data_))); + - sizeof(refCount_))); } static size_t refs(Char * p) { diff --git a/folly/Range.h b/folly/Range.h index ae4310f4..2264d253 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -120,7 +120,7 @@ public: typedef typename std::iterator_traits::reference reference; typedef std::char_traits 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 -const typename Range::size_type Range::npos; +const typename Range::size_type Range::npos = std::string::npos; template void swap(Range& lhs, Range& rhs) { diff --git a/folly/Traits.h b/folly/Traits.h index f2a517f2..7432dec5 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -225,7 +225,7 @@ template struct IsZeroInitializable namespace std { template - class pair; + struct pair; #ifndef _GLIBCXX_USE_FB template class basic_string; diff --git a/folly/json.cpp b/folly/json.cpp index 0d9996ac..710f3b03 100644 --- a/folly/json.cpp +++ b/folly/json.cpp @@ -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"); } diff --git a/folly/small_vector.h b/folly/small_vector.h index 4a0fa276..911f0630 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -100,7 +100,7 @@ struct OneBitMutex; ////////////////////////////////////////////////////////////////////// template -struct small_vector; +class small_vector; ////////////////////////////////////////////////////////////////////// diff --git a/folly/stats/BucketedTimeSeries-defs.h b/folly/stats/BucketedTimeSeries-defs.h index 61bf7f61..28ada12d 100644 --- a/folly/stats/BucketedTimeSeries-defs.h +++ b/folly/stats/BucketedTimeSeries-defs.h @@ -191,7 +191,7 @@ VT BucketedTimeSeries::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::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::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 void BucketedTimeSeries::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; } -- 2.34.1