diff --git a/include/bitsery/adapter/buffer.h b/include/bitsery/adapter/buffer.h index d51601b..ffe428f 100644 --- a/include/bitsery/adapter/buffer.h +++ b/include/bitsery/adapter/buffer.h @@ -48,7 +48,7 @@ namespace bitsery { }; InputBufferAdapter(TIterator beginIt, TIterator endIt) - :InputBufferAdapter(beginIt, std::distance(beginIt, endIt)) { + :InputBufferAdapter(beginIt, static_cast(std::distance(beginIt, endIt))) { } InputBufferAdapter(const InputBufferAdapter&) = delete; @@ -103,6 +103,7 @@ namespace bitsery { } private: + using diff_t = typename std::iterator_traits::difference_type; template void readInternalValue(TValue *data) { @@ -115,17 +116,17 @@ namespace bitsery { template void readInternalValueChecked(TValue *data, std::false_type) { - const auto newOffset = _currOffset + SIZE; + const size_t newOffset = _currOffset + SIZE; assert(newOffset <= _endReadOffset); - std::copy_n(_beginIt + _currOffset, SIZE, data); + std::copy_n(_beginIt + static_cast(_currOffset), SIZE, data); _currOffset = newOffset; } template void readInternalValueChecked(TValue *data, std::true_type) { - const auto newOffset = _currOffset + SIZE; + const size_t newOffset = _currOffset + SIZE; if (newOffset <= _endReadOffset) { - std::copy_n(_beginIt + _currOffset, SIZE, data); + std::copy_n(_beginIt + static_cast(_currOffset), SIZE, data); _currOffset = newOffset; } else { //set everything to zeros @@ -136,16 +137,16 @@ namespace bitsery { } void readInternalBufferChecked(TValue *data, size_t size, std::false_type) { - const auto newOffset = _currOffset + size; + const size_t newOffset = _currOffset + size; assert(newOffset <= _endReadOffset); - std::copy_n(_beginIt + _currOffset, size, data); + std::copy_n(_beginIt + static_cast(_currOffset), size, data); _currOffset = newOffset; } void readInternalBufferChecked(TValue *data, size_t size, std::true_type) { - const auto newOffset = _currOffset + size; + const size_t newOffset = _currOffset + size; if (newOffset <= _endReadOffset) { - std::copy_n(_beginIt + _currOffset, size, data); + std::copy_n(_beginIt + static_cast(_currOffset), size, data); _currOffset = newOffset; } else { //set everything to zeros @@ -229,6 +230,7 @@ namespace bitsery { private: using TResizable = std::integral_constant::isResizable>; + using diff_t = typename std::iterator_traits::difference_type; template void writeInternalValue(const TValue *data) { @@ -259,9 +261,9 @@ namespace bitsery { template void writeInternalValueImpl(const TValue *data, std::true_type) { - const auto newOffset = _currOffset + SIZE; + const size_t newOffset = _currOffset + SIZE; if (newOffset <= _bufferSize) { - std::copy_n(data, SIZE, _beginIt + _currOffset); + std::copy_n(data, SIZE, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } else { traits::BufferAdapterTraits::increaseBufferSize(*_buffer); @@ -271,9 +273,9 @@ namespace bitsery { } void writeInternalBufferImpl(const TValue *data, const size_t size, std::true_type) { - const auto newOffset = _currOffset + size; + const size_t newOffset = _currOffset + size; if (newOffset <= _bufferSize) { - std::copy_n(data, size, _beginIt + _currOffset); + std::copy_n(data, size, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } else { traits::BufferAdapterTraits::increaseBufferSize(*_buffer); @@ -301,16 +303,16 @@ namespace bitsery { template void writeInternalValueImpl(const TValue *data, std::false_type) { - const auto newOffset = _currOffset + SIZE; + const size_t newOffset = _currOffset + SIZE; assert(newOffset <= _bufferSize); - std::copy_n(data, SIZE, _beginIt + _currOffset); + std::copy_n(data, SIZE, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } void writeInternalBufferImpl(const TValue *data, size_t size, std::false_type) { - const auto newOffset = _currOffset + size; + const size_t newOffset = _currOffset + size; assert(newOffset <= _bufferSize); - std::copy_n(data, size, _beginIt + _currOffset); + std::copy_n(data, size, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } diff --git a/include/bitsery/adapter/stream.h b/include/bitsery/adapter/stream.h index b259275..6c5e5d6 100644 --- a/include/bitsery/adapter/stream.h +++ b/include/bitsery/adapter/stream.h @@ -93,7 +93,7 @@ namespace bitsery { } void readChecked(TValue* data, size_t size, std::true_type) { - if (size - static_cast(_ios->rdbuf()->sgetn(data, size)) != _zeroIfNoErrors) { + if (size - static_cast(_ios->rdbuf()->sgetn(data, static_cast(size))) != _zeroIfNoErrors) { *data = {}; if (_zeroIfNoErrors == 0) { error(_ios->rdstate() == std::ios_base::badbit @@ -104,7 +104,7 @@ namespace bitsery { } void readChecked(TValue* data, size_t size, std::false_type) { - _ios->rdbuf()->sgetn(data , size); + _ios->rdbuf()->sgetn(data , static_cast(size)); } std::basic_ios* _ios; @@ -223,6 +223,7 @@ namespace bitsery { private: using TResizable = std::integral_constant::isResizable>; + using diff_t = typename std::iterator_traits::difference_type; template void writeInternalValue(const TValue* data) { @@ -231,14 +232,14 @@ namespace bitsery { writeBufferToStream(); newOffset = SIZE; } - std::copy_n(data, SIZE, _beginIt + _currOffset); + std::copy_n(data, SIZE, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } void writeInternalBuffer(const TValue* data, size_t size) { const auto newOffset = _currOffset + size; if (newOffset <= _bufferSize) { - std::copy_n(data, size, _beginIt + _currOffset); + std::copy_n(data, size, _beginIt + static_cast(_currOffset)); _currOffset = newOffset; } else { writeBufferToStream(); @@ -248,7 +249,7 @@ namespace bitsery { } void writeBufferToStream() { - _ostream->rdbuf()->sputn(std::addressof(*_beginIt), _currOffset); + _ostream->rdbuf()->sputn(std::addressof(*_beginIt), static_cast(_currOffset)); _currOffset = 0; } diff --git a/include/bitsery/deserializer.h b/include/bitsery/deserializer.h index 24c20a4..c83a0b6 100644 --- a/include/bitsery/deserializer.h +++ b/include/bitsery/deserializer.h @@ -141,7 +141,7 @@ namespace bitsery { } auto shiftedRes = static_cast(m_scratch & ((static_cast(1) << bits) - 1)) << (size - bitsLeft); - res |= shiftedRes; + res = static_cast(res | shiftedRes); m_scratch >>= bits; m_scratchBits -= bits; bitsLeft -= bits; @@ -443,8 +443,11 @@ namespace bitsery { void procContainer(It first, It last, std::true_type) { using TValue = typename std::decay::type; using TIntegral = typename details::IntegralFromFundamental::TValue; - if (first != last) - this->_adapter.template readBuffer(reinterpret_cast(&(*first)), std::distance(first, last)); + if (first != last){ + const auto distance = std::distance(first, last); + assert(distance>=0); + this->_adapter.template readBuffer(reinterpret_cast(&(*first)), static_cast(distance)); + } } //process by calling functions @@ -465,7 +468,8 @@ namespace bitsery { void procText(T& str, size_t length) { auto begin = std::begin(str); //end of string, not end of container - auto end = std::next(begin, length); + using diff_t = typename std::iterator_traits::difference_type; + auto end = std::next(begin, static_cast(length)); procContainer(begin, end, std::integral_constant::isContiguous>{}); //null terminated character at the end if (traits::TextTraits::addNUL) diff --git a/include/bitsery/details/adapter_common.h b/include/bitsery/details/adapter_common.h index 153631b..e72d68b 100644 --- a/include/bitsery/details/adapter_common.h +++ b/include/bitsery/details/adapter_common.h @@ -139,7 +139,7 @@ namespace bitsery { using UT = typename std::conditional::type>::type>::type; - return SwapImpl::exec(static_cast(value)); + return static_cast(SwapImpl::exec(static_cast(value))); } /** @@ -176,7 +176,7 @@ namespace bitsery { template<> struct ScratchType { - using type = uint16_t; + using type = uint_fast16_t; }; /** @@ -290,7 +290,8 @@ namespace bitsery { template void swapDataBits(T *v, size_t count, std::true_type) { - std::for_each(v, std::next(v, count), [](T &x) { x = details::swap(x); }); + using diff_t = typename std::iterator_traits::difference_type; + std::for_each(v, std::next(v, static_cast(count)), [](T &x) { x = details::swap(x); }); } template diff --git a/include/bitsery/ext/utils/pointer_utils.h b/include/bitsery/ext/utils/pointer_utils.h index f6f90da..1c9bd5e 100644 --- a/include/bitsery/ext/utils/pointer_utils.h +++ b/include/bitsery/ext/utils/pointer_utils.h @@ -71,7 +71,7 @@ namespace bitsery { StdPolyAlloc alloc{_memResource}; alloc.deallocate(data, 1); } - MemResourceBase* _memResource; + MemResourceBase* _memResource = nullptr; }; //PLC info is internal classes for serializer, and deserializer diff --git a/include/bitsery/ext/value_range.h b/include/bitsery/ext/value_range.h index 0ca92b8..7894ad7 100644 --- a/include/bitsery/ext/value_range.h +++ b/include/bitsery/ext/value_range.h @@ -121,8 +121,8 @@ namespace bitsery { details::SameSizeUnsigned getRangeValue(const T &v, const RangeSpec &r) { using VT = details::SameSizeUnsigned; const VT maxUint = (static_cast(1) << r.bitsRequired) - 1; - const auto ratio = (v - r.min) / (r.max - r.min); - return static_cast(ratio * maxUint); + const T ratio = (v - r.min) / (r.max - r.min); + return static_cast(ratio * static_cast(maxUint)); } template::value>::type * = nullptr> @@ -141,7 +141,7 @@ namespace bitsery { using UIT = details::SameSizeUnsigned; const auto intRep = reinterpret_cast(v); const UIT maxUint = (static_cast(1) << r.bitsRequired) - 1; - v = r.min + (static_cast(intRep) / maxUint) * (r.max - r.min); + v = r.min + (static_cast(intRep) / static_cast(maxUint)) * (r.max - r.min); } template::value>::type * = nullptr> diff --git a/include/bitsery/serializer.h b/include/bitsery/serializer.h index 942cdfe..f2ee019 100644 --- a/include/bitsery/serializer.h +++ b/include/bitsery/serializer.h @@ -120,8 +120,8 @@ namespace bitsery { template void writeBitsInternal(const T &v, size_t size) { constexpr size_t valueSize = details::BitsSize::value; - auto value = v; - auto bitsLeft = size; + T value = v; + size_t bitsLeft = size; while (bitsLeft > 0) { auto bits = (std::min)(bitsLeft, valueSize); _scratch |= static_cast( value ) << _scratchBits; @@ -132,7 +132,7 @@ namespace bitsery { _scratch >>= valueSize; _scratchBits -= valueSize; - value >>= valueSize; + value = static_cast(value >> valueSize); } bitsLeft -= bits; } @@ -452,11 +452,12 @@ namespace bitsery { //process text, template void procText(const T& str, size_t maxSize) { - auto length = traits::TextTraits::length(str); + const size_t length = traits::TextTraits::length(str); assert((length + (traits::TextTraits::addNUL ? 1u : 0u)) <= maxSize); details::writeSize(this->_adapter, length); auto begin = std::begin(str); - procContainer(begin, std::next(begin, length), std::integral_constant::isContiguous>{}); + using diff_t = typename std::iterator_traits::difference_type; + procContainer(begin, std::next(begin, static_cast(length)), std::integral_constant::isContiguous>{}); } //process object types diff --git a/include/bitsery/traits/core/std_defaults.h b/include/bitsery/traits/core/std_defaults.h index b6111b1..f048d8d 100644 --- a/include/bitsery/traits/core/std_defaults.h +++ b/include/bitsery/traits/core/std_defaults.h @@ -56,6 +56,8 @@ namespace bitsery { resizeImpl(container, size, std::is_default_constructible{}); } private: + using diff_t = typename T::difference_type; + static void resizeImpl(T& container, size_t size, std::true_type) { container.resize(size); } @@ -65,7 +67,7 @@ namespace bitsery { container.push_back(::bitsery::Access::create()); } if (oldSize > newSize) { - container.erase(std::next(std::begin(container), newSize), std::end(container)); + container.erase(std::next(std::begin(container), static_cast(newSize)), std::end(container)); } } diff --git a/include/bitsery/traits/forward_list.h b/include/bitsery/traits/forward_list.h index a95f2b9..e42458b 100644 --- a/include/bitsery/traits/forward_list.h +++ b/include/bitsery/traits/forward_list.h @@ -44,6 +44,7 @@ namespace bitsery { resizeImpl(container, size, std::is_default_constructible{}); } private: + using diff_t = typename std::forward_list::difference_type; static void resizeImpl(std::forward_list& container, size_t size, std::true_type) { container.resize(size); } @@ -55,7 +56,7 @@ namespace bitsery { if (oldSize > newSize) { //erase_after must have atleast one element to work if (newSize > 0) - container.erase_after(std::next(std::begin(container), newSize-1)); + container.erase_after(std::next(std::begin(container), static_cast(newSize-1))); else container.clear(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82d9d84..53eb0cc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,7 +39,10 @@ foreach (TestFile ${TestSourceFiles}) add_executable(${TestName} ${TestFile}) target_link_libraries(${TestName} PRIVATE GTest::Main Bitsery::bitsery) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options(${TestName} PRIVATE -Wextra -Wno-missing-braces -Wpedantic -Weffc++ -Wno-c++14-extensions) + target_compile_options(${TestName} PRIVATE -Wextra -Wconversion -Wno-missing-braces -Wpedantic -Weffc++ -Werror) + endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(${TestName} PRIVATE -Wno-c++14-extensions) endif() gtest_discover_tests(${TestName}) diff --git a/tests/brief_syntax.cpp b/tests/brief_syntax.cpp index 0b925fc..1272916 100644 --- a/tests/brief_syntax.cpp +++ b/tests/brief_syntax.cpp @@ -39,11 +39,11 @@ #include #include #else -#if defined(_MSC_VER) +/*#if defined(_MSC_VER) #pragma message("tuple and variant only works with c++17") #else #warning "tuple and variant only works with c++17" -#endif +#endif*/ #endif #include diff --git a/tests/serialization_container.cpp b/tests/serialization_container.cpp index 8d8e5e6..1cdd0e0 100644 --- a/tests/serialization_container.cpp +++ b/tests/serialization_container.cpp @@ -125,7 +125,7 @@ TYPED_TEST(SerializeContainerDynamicSizeArthmeticTypes, CustomFunctionIncrements }); //decrement result by 1, before comparing for eq for (auto &v:this->res) - v -= 1; + v = static_cast(v-1); EXPECT_THAT(ctx.getBufferSize(), Eq(this->getExpectedBufSize(ctx))); EXPECT_THAT(this->res, ContainerEq(this->src)); diff --git a/tests/serialization_ext_std_optional.cpp b/tests/serialization_ext_std_optional.cpp index ef179ab..c3d1a8a 100644 --- a/tests/serialization_ext_std_optional.cpp +++ b/tests/serialization_ext_std_optional.cpp @@ -121,9 +121,9 @@ TEST(SerializeExtensionStdOptional, NoAlignAfterStateWriteRead) { } #else -#if defined(_MSC_VER) +/*#if defined(_MSC_VER) #pragma message("Tests for StdOptional requires C++17") #else #warning "Tests for StdOptional requires C++17" -#endif +#endif*/ #endif diff --git a/tests/serialization_ext_std_smart_ptr.cpp b/tests/serialization_ext_std_smart_ptr.cpp index 0820b1e..8a25c12 100644 --- a/tests/serialization_ext_std_smart_ptr.cpp +++ b/tests/serialization_ext_std_smart_ptr.cpp @@ -71,7 +71,7 @@ void serialize(S& s, Derived& o) { } struct MoreDerived : Derived { - int8_t z{}; + uint8_t z{}; MoreDerived() = default; diff --git a/tests/serialization_ext_std_tuple.cpp b/tests/serialization_ext_std_tuple.cpp index 805d940..1d7f95d 100644 --- a/tests/serialization_ext_std_tuple.cpp +++ b/tests/serialization_ext_std_tuple.cpp @@ -119,9 +119,9 @@ TEST(SerializeExtensionStdTuple, NonDefaultConstructable) { } #else -#if defined(_MSC_VER) +/*#if defined(_MSC_VER) #pragma message("Tests for StdTuple requires C++17") #else #warning "Tests for StdTuple requires C++17" -#endif +#endif*/ #endif \ No newline at end of file diff --git a/tests/serialization_ext_std_variant.cpp b/tests/serialization_ext_std_variant.cpp index 2baafd2..160b134 100644 --- a/tests/serialization_ext_std_variant.cpp +++ b/tests/serialization_ext_std_variant.cpp @@ -168,9 +168,9 @@ TEST(SerializeExtensionStdVariant, CorrectlyHandleMonoState) { } #else -#if defined(_MSC_VER) +/*#if defined(_MSC_VER) #pragma message("Tests for StdVariant requires C++17") #else #warning "Tests for StdVariant requires C++17" -#endif +#endif*/ #endif