Commit 71a467ce authored by octal's avatar octal

Fixed a bunch of errors reported by clang that were not reported by gcc

parent 7e2866dd
cmake_minimum_required (VERSION 2.8.7) cmake_minimum_required (VERSION 2.8.7)
project (restgear) project (restgear)
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
add_definitions(-std=c++0x) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
add_subdirectory (src) add_subdirectory (src)
......
...@@ -437,6 +437,7 @@ namespace Async { ...@@ -437,6 +437,7 @@ namespace Async {
class Resolver { class Resolver {
public: public:
Resolver(const std::shared_ptr<Private::Core> &core) Resolver(const std::shared_ptr<Private::Core> &core)
: core_(core) : core_(core)
{ } { }
...@@ -484,11 +485,11 @@ namespace Async { ...@@ -484,11 +485,11 @@ namespace Async {
class Rejection { class Rejection {
public: public:
Rejection(const std::shared_ptr<Private::Core>& core) Rejection(const std::shared_ptr<Private::Core>& core)
: core_(core) : core_(core)
{ } { }
template<typename Exc> template<typename Exc>
bool operator()(Exc exc) const { bool operator()(Exc exc) const {
if (core_->state != State::Pending) if (core_->state != State::Pending)
...@@ -508,8 +509,8 @@ namespace Async { ...@@ -508,8 +509,8 @@ namespace Async {
}; };
static constexpr Private::IgnoreException IgnoreException; static constexpr Private::IgnoreException IgnoreException{};
static constexpr Private::NoExcept NoExcept; static constexpr Private::NoExcept NoExcept{};
template<typename T> template<typename T>
class Promise : public PromiseBase class Promise : public PromiseBase
...@@ -812,16 +813,16 @@ namespace Async { ...@@ -812,16 +813,16 @@ namespace Async {
typename Results = std::vector<ValueType> typename Results = std::vector<ValueType>
> >
Promise<Results> whenAll(Iterator first, Iterator last) { Promise<Results> whenAll(Iterator first, Iterator last) {
return Promise<Results>([=](Resolver& resolve, Rejection& rejection) { /* @Security, assert that last >= first */
struct Data { struct Data {
Data(const size_t total, public:
Resolver resolver, Data(size_t total, Resolver resolver, Rejection rejection)
Rejection rejection)
: total(total) : total(total)
, resolved(0) , resolved(0)
, rejected(false) , rejected(false)
, resolve(std::move(resolver)) , resolve(resolver)
, reject(std::move(rejection)) , reject(rejection)
{ {
results.resize(total); results.resize(total);
} }
...@@ -830,16 +831,19 @@ namespace Async { ...@@ -830,16 +831,19 @@ namespace Async {
std::atomic<size_t> resolved; std::atomic<size_t> resolved;
std::atomic<bool> rejected; std::atomic<bool> rejected;
Results results;
Resolver resolve; Resolver resolve;
Rejection reject; Rejection reject;
Results results;
}; };
return Promise<Results>([=](Resolver& resolve, Rejection& rejection) {
auto data = std::make_shared<Data>( auto data = std::make_shared<Data>(
std::distance(first, last), static_cast<size_t>(std::distance(first, last)),
resolve, std::move(resolve),
rejection std::move(rejection)
); );
size_t index = 0; size_t index = 0;
......
...@@ -33,6 +33,8 @@ template< class CharT, class Traits> ...@@ -33,6 +33,8 @@ template< class CharT, class Traits>
std::basic_ostream<CharT, Traits>& crlf(std::basic_ostream<CharT, Traits>& os) { std::basic_ostream<CharT, Traits>& crlf(std::basic_ostream<CharT, Traits>& os) {
static constexpr char CRLF[] = {0xD, 0xA}; static constexpr char CRLF[] = {0xD, 0xA};
os.write(CRLF, 2); os.write(CRLF, 2);
return os;
} }
// 4. HTTP Message // 4. HTTP Message
......
...@@ -25,6 +25,7 @@ namespace { ...@@ -25,6 +25,7 @@ namespace {
bool parseAscTimeDate(std::tm& tm, const char* str, size_t len) { bool parseAscTimeDate(std::tm& tm, const char* str, size_t len) {
char *p = strptime(str, "%a %b %d %H:%M:%S %Y", &tm); char *p = strptime(str, "%a %b %d %H:%M:%S %Y", &tm);
return p != NULL;
} }
} // anonymous namespace } // anonymous namespace
...@@ -139,6 +140,7 @@ std::ostream& operator<<(std::ostream& os, Method method) { ...@@ -139,6 +140,7 @@ std::ostream& operator<<(std::ostream& os, Method method) {
std::ostream& operator<<(std::ostream& os, Code code) { std::ostream& operator<<(std::ostream& os, Code code) {
os << codeString(code); os << codeString(code);
return os;
} }
HttpError::HttpError(Code code, std::string reason) HttpError::HttpError(Code code, std::string reason)
......
...@@ -171,7 +171,7 @@ CacheControl::parseRaw(const char* str, size_t len) { ...@@ -171,7 +171,7 @@ CacheControl::parseRaw(const char* str, size_t len) {
} }
int c; int c;
while ((c = cursor.current()) != StreamCursor::Eof && c == ',' || c == ' ') while ((c = cursor.current()) != StreamCursor::Eof && (c == ',' || c == ' '))
cursor.advance(1); cursor.advance(1);
} }
...@@ -209,6 +209,8 @@ CacheControl::write(std::ostream& os) const { ...@@ -209,6 +209,8 @@ CacheControl::write(std::ostream& os) const {
return "min-fresh"; return "min-fresh";
case CacheDirective::SMaxAge: case CacheDirective::SMaxAge:
return "s-maxage"; return "s-maxage";
case CacheDirective::Ext:
return "";
} }
}; };
...@@ -219,8 +221,9 @@ CacheControl::write(std::ostream& os) const { ...@@ -219,8 +221,9 @@ CacheControl::write(std::ostream& os) const {
case CacheDirective::MinFresh: case CacheDirective::MinFresh:
case CacheDirective::SMaxAge: case CacheDirective::SMaxAge:
return true; return true;
} default:
return false; return false;
}
}; };
for (std::vector<CacheDirective>::size_type i = 0; i < directives_.size(); ++i) { for (std::vector<CacheDirective>::size_type i = 0; i < directives_.size(); ++i) {
...@@ -312,7 +315,10 @@ Host::parse(const std::string& data) { ...@@ -312,7 +315,10 @@ Host::parse(const std::string& data) {
void void
Host::write(std::ostream& os) const { Host::write(std::ostream& os) const {
os << host_; os << host_;
if (port_ != -1) { /* @Clarity @Robustness: maybe a found a literal different than zero
to represent a null port ?
*/
if (port_ != 0) {
os << ":" << port_; os << ":" << port_;
} }
} }
......
...@@ -308,8 +308,6 @@ public: ...@@ -308,8 +308,6 @@ public:
NAME("Host"); NAME("Host");
Host() Host()
: host_()
, port_(-1)
{ } { }
explicit Host(const std::string& host, Net::Port port = 80) explicit Host(const std::string& host, Net::Port port = 80)
......
...@@ -81,6 +81,7 @@ Collection::add(const std::shared_ptr<Header>& header) { ...@@ -81,6 +81,7 @@ Collection::add(const std::shared_ptr<Header>& header) {
Collection& Collection&
Collection::addRaw(const Raw& raw) { Collection::addRaw(const Raw& raw) {
rawHeaders.insert(std::make_pair(raw.name(), raw)); rawHeaders.insert(std::make_pair(raw.name(), raw));
return *this;
} }
std::shared_ptr<const Header> std::shared_ptr<const Header>
......
...@@ -228,6 +228,8 @@ MediaType::toString() const { ...@@ -228,6 +228,8 @@ MediaType::toString() const {
return str; return str;
MIME_TYPES MIME_TYPES
#undef TYPE #undef TYPE
default:
return "";
} }
}; };
...@@ -238,6 +240,8 @@ MediaType::toString() const { ...@@ -238,6 +240,8 @@ MediaType::toString() const {
return str; return str;
MIME_SUBTYPES MIME_SUBTYPES
#undef TYPE #undef TYPE
default:
return "";
} }
}; };
...@@ -248,6 +252,8 @@ MediaType::toString() const { ...@@ -248,6 +252,8 @@ MediaType::toString() const {
return "+" str; return "+" str;
MIME_SUFFIXES MIME_SUFFIXES
#undef SUFFIX #undef SUFFIX
default:
return "";
} }
}; };
......
...@@ -96,14 +96,14 @@ digitsCount(T val) { ...@@ -96,14 +96,14 @@ digitsCount(T val) {
template<> template<>
struct Size<const char*> { struct Size<const char*> {
size_t operator()(const char *s) { size_t operator()(const char *s) const {
return std::strlen(s); return std::strlen(s);
} }
}; };
template<size_t N> template<size_t N>
struct Size<char[N]> { struct Size<char[N]> {
constexpr size_t operator()(const char (&arr)[N]) { constexpr size_t operator()(const char (&arr)[N]) const {
// We omit the \0 // We omit the \0
return N - 1; return N - 1;
} }
...@@ -112,7 +112,7 @@ struct Size<char[N]> { ...@@ -112,7 +112,7 @@ struct Size<char[N]> {
#define DEFINE_INTEGRAL_SIZE(Int) \ #define DEFINE_INTEGRAL_SIZE(Int) \
template<> \ template<> \
struct Size<Int> { \ struct Size<Int> { \
size_t operator()(Int val) { \ size_t operator()(Int val) const { \
return digitsCount(val); \ return digitsCount(val); \
} \ } \
} }
...@@ -128,14 +128,14 @@ DEFINE_INTEGRAL_SIZE(int64_t); ...@@ -128,14 +128,14 @@ DEFINE_INTEGRAL_SIZE(int64_t);
template<> template<>
struct Size<bool> { struct Size<bool> {
constexpr size_t operator()(bool) { constexpr size_t operator()(bool) const {
return 1; return 1;
} }
}; };
template<> template<>
struct Size<char> { struct Size<char> {
constexpr size_t operator()(char) { constexpr size_t operator()(char) const {
return 1; return 1;
} }
}; };
......
...@@ -14,11 +14,14 @@ ...@@ -14,11 +14,14 @@
#include <tuple> #include <tuple>
#include <functional> #include <functional>
template<typename T> class Optional;
namespace types { namespace types {
template<typename T> template<typename T>
class Some { class Some {
public: public:
template<typename U> friend class Optional; template<typename U> friend class ::Optional;
Some(const T &val) : val_(val) { } Some(const T &val) : val_(val) { }
Some(T &&val) : val_(std::move(val)) { } Some(T &&val) : val_(std::move(val)) { }
...@@ -155,6 +158,8 @@ public: ...@@ -155,6 +158,8 @@ public:
} }
none_flag = NoneMarker; none_flag = NoneMarker;
} }
return *this;
} }
......
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