Commit 86d219c3 authored by Philip Pronin's avatar Philip Pronin Committed by Jordan DeLong

fix some of the warning/errors clang 3.1 reports

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
parent 7fb1e3d7
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -185,7 +185,7 @@ typename std::enable_if< ...@@ -185,7 +185,7 @@ typename std::enable_if<
== 2 == 2
>::type >::type
addBenchmark(const char* file, const char* name, Lambda&& lambda) { addBenchmark(const char* file, const char* name, Lambda&& lambda) {
auto execute = [=](unsigned int times) { auto execute = [=](unsigned int times) -> uint64_t {
BenchmarkSuspender::nsSpent = 0; BenchmarkSuspender::nsSpent = 0;
timespec start, end; timespec start, end;
......
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); ...@@ -43,7 +43,9 @@ const size_t kMaxBinaryLength = 8 * sizeof(uintmax_t);
template <class Uint> template <class Uint>
size_t uintToHex(char* buffer, size_t bufLen, Uint v, size_t uintToHex(char* buffer, size_t bufLen, Uint v,
const char (&repr)[256][2]) { 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; auto b = v & 0xff;
bufLen -= 2; bufLen -= 2;
buffer[bufLen] = repr[b][0]; buffer[bufLen] = repr[b][0];
...@@ -85,7 +87,9 @@ inline size_t uintToHexUpper(char* buffer, size_t bufLen, Uint v) { ...@@ -85,7 +87,9 @@ inline size_t uintToHexUpper(char* buffer, size_t bufLen, Uint v) {
template <class Uint> template <class Uint>
size_t uintToOctal(char* buffer, size_t bufLen, Uint v) { size_t uintToOctal(char* buffer, size_t bufLen, Uint v) {
auto& repr = formatOctal; 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; auto b = v & 0x1ff;
bufLen -= 3; bufLen -= 3;
buffer[bufLen] = repr[b][0]; buffer[bufLen] = repr[b][0];
...@@ -117,7 +121,7 @@ size_t uintToBinary(char* buffer, size_t bufLen, Uint v) { ...@@ -117,7 +121,7 @@ size_t uintToBinary(char* buffer, size_t bufLen, Uint v) {
buffer[--bufLen] = '0'; buffer[--bufLen] = '0';
return bufLen; return bufLen;
} }
for (; v; v >>= 8) { for (; v; v >>= 7, v >>= 1) {
auto b = v & 0xff; auto b = v & 0xff;
bufLen -= 8; bufLen -= 8;
memcpy(buffer + bufLen, &(repr[b][0]), 8); memcpy(buffer + bufLen, &(repr[b][0]), 8);
......
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <limits> #include <limits>
......
...@@ -442,12 +442,6 @@ void Subprocess::sendSignal(int signal) { ...@@ -442,12 +442,6 @@ void Subprocess::sendSignal(int signal) {
} }
namespace { 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) { std::pair<const uint8_t*, size_t> queueFront(const IOBufQueue& queue) {
auto* p = queue.front(); auto* p = queue.front();
...@@ -544,7 +538,7 @@ std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf( ...@@ -544,7 +538,7 @@ std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf(
IOBufQueue data) { IOBufQueue data) {
std::pair<IOBufQueue, IOBufQueue> out; std::pair<IOBufQueue, IOBufQueue> out;
auto readCallback = [&] (int pfd, int cfd) { auto readCallback = [&] (int pfd, int cfd) -> bool {
if (cfd == 1 && flags.readStdout_) { if (cfd == 1 && flags.readStdout_) {
return handleRead(pfd, out.first); return handleRead(pfd, out.first);
} else if (cfd == 2 && flags.readStderr_) { } else if (cfd == 2 && flags.readStderr_) {
...@@ -556,7 +550,7 @@ std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf( ...@@ -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_) { if (cfd == 0 && flags.writeStdin_) {
return handleWrite(pfd, data); return handleWrite(pfd, data);
} else { } else {
......
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -175,7 +175,7 @@ class GenImpl : public FBounded<Self> { ...@@ -175,7 +175,7 @@ class GenImpl : public FBounded<Self> {
*/ */
template<class Body> template<class Body>
void foreach(Body&& body) const { void foreach(Body&& body) const {
this->self().apply([&](Value value) { this->self().apply([&](Value value) -> bool {
body(std::forward<Value>(value)); body(std::forward<Value>(value));
return true; return true;
}); });
...@@ -703,7 +703,7 @@ class Until : public Operator<Until<Predicate>> { ...@@ -703,7 +703,7 @@ class Until : public Operator<Until<Predicate>> {
*/ */
class Take : public Operator<Take> { class Take : public Operator<Take> {
size_t count_; size_t count_;
public: public:
explicit Take(size_t count) explicit Take(size_t count)
: count_(count) {} : count_(count) {}
...@@ -756,7 +756,7 @@ public: ...@@ -756,7 +756,7 @@ public:
*/ */
class Skip : public Operator<Skip> { class Skip : public Operator<Skip> {
size_t count_; size_t count_;
public: public:
explicit Skip(size_t count) explicit Skip(size_t count)
: count_(count) {} : count_(count) {}
...@@ -835,7 +835,7 @@ class Order : public Operator<Order<Selector, Comparer>> { ...@@ -835,7 +835,7 @@ class Order : public Operator<Order<Selector, Comparer>> {
Selector selector_; Selector selector_;
Comparer comparer_; Comparer comparer_;
public: public:
Order(const Selector& selector = Selector(), explicit Order(const Selector& selector = Selector(),
const Comparer& comparer = Comparer()) const Comparer& comparer = Comparer())
: selector_(selector) , comparer_(comparer) {} : selector_(selector) , comparer_(comparer) {}
...@@ -1007,6 +1007,8 @@ class FoldLeft : public Operator<FoldLeft<Seed, Fold>> { ...@@ -1007,6 +1007,8 @@ class FoldLeft : public Operator<FoldLeft<Seed, Fold>> {
*/ */
class First : public Operator<First> { class First : public Operator<First> {
public: public:
First() { }
template<class Source, template<class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
...@@ -1033,6 +1035,8 @@ class First : public Operator<First> { ...@@ -1033,6 +1035,8 @@ class First : public Operator<First> {
*/ */
class Any : public Operator<Any> { class Any : public Operator<Any> {
public: public:
Any() { }
template<class Source, template<class Source,
class Value> class Value>
bool compose(const GenImpl<Value, Source>& source) const { bool compose(const GenImpl<Value, Source>& source) const {
...@@ -1061,7 +1065,7 @@ template<class Reducer> ...@@ -1061,7 +1065,7 @@ template<class Reducer>
class Reduce : public Operator<Reduce<Reducer>> { class Reduce : public Operator<Reduce<Reducer>> {
Reducer reducer_; Reducer reducer_;
public: public:
Reduce(const Reducer& reducer) explicit Reduce(const Reducer& reducer)
: reducer_(reducer) : reducer_(reducer)
{} {}
...@@ -1093,6 +1097,8 @@ class Reduce : public Operator<Reduce<Reducer>> { ...@@ -1093,6 +1097,8 @@ class Reduce : public Operator<Reduce<Reducer>> {
*/ */
class Count : public Operator<Count> { class Count : public Operator<Count> {
public: public:
Count() { }
template<class Source, template<class Source,
class Value> class Value>
size_t compose(const GenImpl<Value, Source>& source) const { size_t compose(const GenImpl<Value, Source>& source) const {
...@@ -1112,6 +1118,8 @@ class Count : public Operator<Count> { ...@@ -1112,6 +1118,8 @@ class Count : public Operator<Count> {
*/ */
class Sum : public Operator<Sum> { class Sum : public Operator<Sum> {
public: public:
Sum() { }
template<class Source, template<class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
...@@ -1141,7 +1149,7 @@ class Min : public Operator<Min<Selector, Comparer>> { ...@@ -1141,7 +1149,7 @@ class Min : public Operator<Min<Selector, Comparer>> {
Selector selector_; Selector selector_;
Comparer comparer_; Comparer comparer_;
public: public:
Min(const Selector& selector = Selector(), explicit Min(const Selector& selector = Selector(),
const Comparer& comparer = Comparer()) const Comparer& comparer = Comparer())
: selector_(selector) : selector_(selector)
, comparer_(comparer) , comparer_(comparer)
...@@ -1211,6 +1219,8 @@ class Append : public Operator<Append<Collection>> { ...@@ -1211,6 +1219,8 @@ class Append : public Operator<Append<Collection>> {
template<class Collection> template<class Collection>
class Collect : public Operator<Collect<Collection>> { class Collect : public Operator<Collect<Collection>> {
public: public:
Collect() { }
template<class Value, template<class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
...@@ -1243,6 +1253,8 @@ template<template<class, class> class Container, ...@@ -1243,6 +1253,8 @@ template<template<class, class> class Container,
template<class> class Allocator> template<class> class Allocator>
class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> { class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
public: public:
CollectTemplate() { }
template<class Value, template<class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type, class StorageType = typename std::decay<Value>::type,
...@@ -1255,6 +1267,7 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> { ...@@ -1255,6 +1267,7 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
return collection; return collection;
} }
}; };
/** /**
* Concat - For flattening generators of generators. * Concat - For flattening generators of generators.
* *
...@@ -1272,7 +1285,9 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> { ...@@ -1272,7 +1285,9 @@ class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
* | as<std::set>(); * | as<std::set>();
*/ */
class Concat : public Operator<Concat> { class Concat : public Operator<Concat> {
public: public:
Concat() { }
template<class Inner, template<class Inner,
class Source, class Source,
class InnerValue = typename std::decay<Inner>::type::ValueType> class InnerValue = typename std::decay<Inner>::type::ValueType>
...@@ -1326,7 +1341,9 @@ public: ...@@ -1326,7 +1341,9 @@ public:
* | as<std::set>(); * | as<std::set>();
*/ */
class RangeConcat : public Operator<RangeConcat> { class RangeConcat : public Operator<RangeConcat> {
public: public:
RangeConcat() { }
template<class Source, template<class Source,
class Range, class Range,
class InnerValue = typename ValueTypeOfRange<Range>::RefType> class InnerValue = typename ValueTypeOfRange<Range>::RefType>
...@@ -1348,7 +1365,7 @@ public: ...@@ -1348,7 +1365,7 @@ public:
template<class Handler> template<class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
return source_.apply([&](Range range) { return source_.apply([&](Range range) -> bool {
for (auto& value : range) { for (auto& value : range) {
if (!handler(value)) { if (!handler(value)) {
return false; return false;
......
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -186,15 +186,6 @@ TEST(Format, Simple) { ...@@ -186,15 +186,6 @@ TEST(Format, Simple) {
EXPECT_EQ("42 23 hello worldXX", s); 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) { TEST(Format, Float) {
double d = 1; double d = 1;
EXPECT_EQ("1", fstr("{}", 1.0)); EXPECT_EQ("1", fstr("{}", 1.0));
......
/* /*
* Copyright 2012 Facebook, Inc. * Copyright 2013 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "folly/stats/BucketedTimeSeries.h" #include "folly/stats/BucketedTimeSeries.h"
#include "folly/stats/BucketedTimeSeries-defs.h" #include "folly/stats/BucketedTimeSeries-defs.h"
...@@ -475,7 +476,7 @@ TEST(BucketedTimeSeries, forEachBucket) { ...@@ -475,7 +476,7 @@ TEST(BucketedTimeSeries, forEachBucket) {
vector<BucketInfo> info; vector<BucketInfo> info;
auto fn = [&](const Bucket& bucket, seconds bucketStart, auto fn = [&](const Bucket& bucket, seconds bucketStart,
seconds bucketEnd) { seconds bucketEnd) -> bool {
info.emplace_back(&bucket, bucketStart, bucketEnd); info.emplace_back(&bucket, bucketStart, bucketEnd);
return true; return true;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment