Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion warnings #109

Merged
merged 8 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include(Hunter/init)
project(intx LANGUAGES CXX)
set(PROJECT_VERSION 0.4.0-dev)

cable_configure_compiler(NO_CONVERSION_WARNINGS NO_STACK_PROTECTION)
cable_configure_compiler(NO_STACK_PROTECTION)

if(INTX_TESTING)
enable_testing()
Expand Down
45 changes: 22 additions & 23 deletions include/intx/int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ constexpr unsigned clz_generic(uint32_t x) noexcept
unsigned n = 32;
for (int i = 4; i >= 0; --i)
{
const auto s = 1 << i;
const auto s = unsigned{1} << i;
const auto hi = x >> s;
if (hi != 0)
{
Expand All @@ -386,7 +386,7 @@ constexpr unsigned clz_generic(uint64_t x) noexcept
unsigned n = 64;
for (int i = 5; i >= 0; --i)
{
const auto s = 1 << i;
const auto s = unsigned{1} << i;
const auto hi = x >> s;
if (hi != 0)
{
Expand Down Expand Up @@ -730,47 +730,46 @@ struct numeric_limits<intx::uint<N>>

namespace intx
{
constexpr inline int from_dec_digit(char c)
{
return (c >= '0' && c <= '9') ? c - '0' :
throw std::invalid_argument{std::string{"Invalid digit: "} + c};
}

constexpr inline int from_hex_digit(char c)
{
if (c >= 'a' && c <= 'f')
return c - ('a' - 10);
if (c >= 'A' && c <= 'F')
return c - ('A' - 10);
return from_dec_digit(c);
}

template <typename Int>
constexpr Int from_string(const char* s)
{
using namespace std::literals;

auto x = Int{};
int num_digits = 0;

if (s[0] == '0' && s[1] == 'x')
{
s += 2;
while (auto d = *s++)
while (const auto c = *s++)
{
if (++num_digits > int{sizeof(x) * 2})
throw std::overflow_error{"Integer overflow"};

x <<= 4;
if (d >= '0' && d <= '9')
d -= '0';
else if (d >= 'a' && d <= 'f')
d -= 'a' - 10;
else if (d >= 'A' && d <= 'F')
d -= 'A' - 10;
else
throw std::invalid_argument{"Invalid literal character: "s + d};
x |= d;
x = (x << 4) | from_hex_digit(c);
}
return x;
}

while (auto d = *s++)
while (const auto c = *s++)
{
if (num_digits++ > std::numeric_limits<Int>::digits10)
throw std::overflow_error{"Integer overflow"};

x = constexpr_mul(x, Int{10});
if (d >= '0' && d <= '9')
d -= '0';
else
throw std::invalid_argument{"Invalid literal character: "s + d};
x += d;
const auto d = from_dec_digit(c);
x = constexpr_mul(x, Int{10}) + d;
if (x < d)
throw std::overflow_error{"Integer overflow"};
}
Expand Down
2 changes: 1 addition & 1 deletion include/intx/intx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ inline Target narrow_cast(const Int& x) noexcept
template <unsigned N>
constexpr uint<N> operator>>(const uint<N>& x, unsigned shift) noexcept
{
constexpr auto half_bits = sizeof(x) * 4;
constexpr auto half_bits = N / 2;

if (shift < half_bits)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/intx/div.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct normalized_div_args
typename uint<N>::word_type numerator_ex;
int num_denominator_words;
int num_numerator_words;
int shift;
unsigned shift;
};

template <typename IntT>
Expand Down
2 changes: 2 additions & 0 deletions test/experimental/div.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <cstring>
#include <tuple>

#pragma GCC diagnostic ignored "-Wsign-conversion"


#if 0
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/test_intx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ TYPED_TEST(uint_test, be_trunc)
EXPECT_EQ(str, "Hello Solaris!!");
}

template <unsigned M>
template <size_t M>
struct storage
{
uint8_t bytes[M];
Expand Down
4 changes: 2 additions & 2 deletions test/utils/gmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ template <typename Int>
inline div_result<Int> udivrem(const Int& x, const Int& y) noexcept
{
// Skip dividend's leading zero limbs.
constexpr size_t x_limbs = sizeof(Int) / sizeof(mp_limb_t);
const size_t y_limbs = count_significant_words<mp_limb_t>(y);
constexpr auto x_limbs = sizeof(Int) / sizeof(mp_limb_t);
const auto y_limbs = static_cast<mp_size_t>(count_significant_words<mp_limb_t>(y));

Int q, r;
auto p_q = (mp_ptr)&q;
Expand Down