From 10a6e7637552a86be401700d38c08fa165aa2bbf Mon Sep 17 00:00:00 2001 From: vogel76 Date: Wed, 29 Jan 2014 12:51:45 +0100 Subject: [PATCH 1/2] [BW]: [Ign] Fixed compile errors (missing < operator on fc::enum_type [BW]: [Ign] Eliminated some annoying compiler warnings. --- include/fc/io/enum_type.hpp | 25 ++++++++++++++++--------- include/fc/io/raw.hpp | 4 ++-- include/fc/time.hpp | 6 ++++++ include/fc/uint128.hpp | 6 ++++++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/fc/io/enum_type.hpp b/include/fc/io/enum_type.hpp index 52a9961..ca2cc24 100644 --- a/include/fc/io/enum_type.hpp +++ b/include/fc/io/enum_type.hpp @@ -24,16 +24,23 @@ namespace fc enum_type& operator=( IntType i ) { value = (EnumType)i; return *this;} enum_type& operator=( EnumType i ) { value = i; return *this;} - friend bool operator==( enum_type e, IntType i ) { return e.value == (EnumType)i; } - friend bool operator==( enum_type e, EnumType i ) { return e.value == i; } + bool operator<(const enum_type& e) const { return value < e.value;} + bool operator>(const enum_type& e) const { return value > e.value;} + + bool operator<=(const enum_type& e) const { return value <= e.value;} + bool operator>=(const enum_type& e) const { return value >= e.value;} + + friend bool operator==( const enum_type& e, IntType i ){ return e.value == (EnumType)i;} + friend bool operator==( const enum_type& e, EnumType i ){ return e.value == i; } + + friend bool operator==( const enum_type& e, const enum_type& i ){ return e.value == i.value; } + friend bool operator==( IntType i, const enum_type& e){ return e.value == (EnumType)i; } + friend bool operator==( EnumType i, const enum_type& e ){ return e.value == i; } + + friend bool operator!=( const enum_type& e, IntType i ){ return e.value != (EnumType)i;} + friend bool operator!=( const enum_type& e, EnumType i ){ return e.value != i; } + friend bool operator!=( const enum_type& e, const enum_type& i ){ return e.value != i.value; } - friend bool operator==( enum_type e, enum_type i ) { return e.value == i.value; } - friend bool operator==( IntType i, enum_type e) { return e.value == (EnumType)i; } - friend bool operator==( EnumType i, enum_type e ) { return e.value == i; } - - friend bool operator!=( enum_type e, IntType i ) { return e.value != (EnumType)i; } - friend bool operator!=( enum_type e, EnumType i ) { return e.value != i; } - friend bool operator!=( enum_type e, enum_type i ) { return e.value != i.value; } EnumType value; }; diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 7c84cd6..874483d 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -106,7 +106,7 @@ namespace fc { v |= uint32_t(uint8_t(b) & 0x7f) << by; by += 7; } while( uint8_t(b) & 0x80 ); - vi.value = v; + vi.value = static_cast(v); } template inline void pack( Stream& s, const char* v ) { pack( s, fc::string(v) ); } @@ -153,7 +153,7 @@ namespace fc { // bool template inline void pack( Stream& s, const bool& v ) { pack( s, uint8_t(v) ); } - template inline void unpack( Stream& s, bool& v ) { uint8_t b; unpack( s, b ); v=b; } + template inline void unpack( Stream& s, bool& v ) { uint8_t b; unpack( s, b ); v=(b!=0); } namespace detail { diff --git a/include/fc/time.hpp b/include/fc/time.hpp index dd28bfc..f2e4024 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -3,6 +3,9 @@ #include #include +#pragma warning (push) +#pragma warning (disable : 4244) + namespace fc { class microseconds { public: @@ -87,3 +90,6 @@ namespace fc { typedef fc::optional otime_point; } + +#pragma warning (pop) + diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index 2d84c4f..0577e3c 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -2,6 +2,9 @@ #include #include +#pragma warning (push) +#pragma warning (disable : 4244) + namespace fc { class bigint; @@ -110,3 +113,6 @@ namespace std } }; } + +#pragma warning (pop) + From d2eefb7ed4d36e5d450444a6c873a40896b80c25 Mon Sep 17 00:00:00 2001 From: vogel76 Date: Wed, 29 Jan 2014 13:08:37 +0100 Subject: [PATCH 2/2] [BW]: [Ign] #pragma warning enclosed into _MSC_VER to avoid gcc complaining [BW]: [NIP] Added LLCONST and ULLCONST macros to safely declare large literals incl. setting its type and avoid gcc compile error this way. --- include/fc/time.hpp | 11 +++++++---- include/fc/uint128.hpp | 11 +++++++---- include/fc/utility.hpp | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/fc/time.hpp b/include/fc/time.hpp index f2e4024..c5ae58a 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -3,8 +3,10 @@ #include #include -#pragma warning (push) -#pragma warning (disable : 4244) +#ifdef _MSC_VER + #pragma warning (push) + #pragma warning (disable : 4244) +#endif //// _MSC_VER namespace fc { class microseconds { @@ -91,5 +93,6 @@ namespace fc { typedef fc::optional otime_point; } -#pragma warning (pop) - +#ifdef _MSC_VER + #pragma warning (pop) +#endif /// #ifdef _MSC_VER diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index 0577e3c..aab14f2 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -2,8 +2,10 @@ #include #include -#pragma warning (push) -#pragma warning (disable : 4244) +#ifdef _MSC_VER + #pragma warning (push) + #pragma warning (disable : 4244) +#endif //// _MSC_VER namespace fc { @@ -114,5 +116,6 @@ namespace std }; } -#pragma warning (pop) - +#ifdef _MSC_VER + #pragma warning (pop) +#endif ///_MSC_VER diff --git a/include/fc/utility.hpp b/include/fc/utility.hpp index 0c6c77e..098d9d0 100644 --- a/include/fc/utility.hpp +++ b/include/fc/utility.hpp @@ -59,3 +59,7 @@ namespace fc { a = fc::move(b); b = fc::move(tmp); } + +#define LLCONST(constant) static_cast(constant##ll) +#define ULLCONST(constant) static_cast(constant##ull) +