Skip to content

Commit 297cc62

Browse files
committed
std::distance returns a signed type, wrap in explicit cast
Visual Studio warns about signed/unsigned conversion and limited range of types.
1 parent 46010c3 commit 297cc62

File tree

12 files changed

+37
-22
lines changed

12 files changed

+37
-22
lines changed

jbmc/unit/pointer-analysis/custom_value_set_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef
147147
#define TEST_FUNCTION_NAME TEST_PREFIX "test:()V"
148148
#define TEST_LOCAL_PREFIX TEST_FUNCTION_NAME "::"
149149

150-
static std::size_t
150+
static std::ptrdiff_t
151151
exprs_with_id(const std::vector<exprt> &exprs, const irep_idt &id)
152152
{
153153
return std::count_if(

src/cpp/cpp_token_buffer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void cpp_token_buffert::Insert(const cpp_tokent &token)
119119

120120
tokens.push_back(token);
121121

122-
token_vector.insert(token_vector.begin()+current_pos,
123-
--tokens.end());
122+
token_vector.insert(
123+
token_vector.begin() + static_cast<std::ptrdiff_t>(current_pos),
124+
--tokens.end());
124125
}

src/goto-instrument/goto_program2code.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,8 @@ void goto_program2codet::cleanup_code_block(
15591559
operands.size()>1 && i<operands.size();
15601560
) // no ++i
15611561
{
1562-
exprt::operandst::iterator it=operands.begin()+i;
1562+
exprt::operandst::iterator it =
1563+
operands.begin() + static_cast<std::ptrdiff_t>(i);
15631564
// remove skip
15641565
if(to_code(*it).get_statement()==ID_skip &&
15651566
it->source_location().get_comment().empty())
@@ -1579,9 +1580,11 @@ void goto_program2codet::cleanup_code_block(
15791580

15801581
if(!has_decl)
15811582
{
1582-
operands.insert(operands.begin()+i+1,
1583-
it->operands().begin(), it->operands().end());
1584-
operands.erase(operands.begin()+i);
1583+
operands.insert(
1584+
operands.begin() + static_cast<std::ptrdiff_t>(i) + 1,
1585+
it->operands().begin(),
1586+
it->operands().end());
1587+
operands.erase(operands.begin() + static_cast<std::ptrdiff_t>(i));
15851588
// no ++i
15861589
}
15871590
else

src/solvers/flattening/boolbv_complex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bvt boolbvt::convert_complex_imag(const complex_imag_exprt &expr)
5151

5252
bvt bv = convert_bv(expr.op(), width * 2);
5353

54-
bv.erase(bv.begin(), bv.begin()+width);
54+
bv.erase(bv.begin(), bv.begin() + static_cast<std::ptrdiff_t>(width));
5555

5656
return bv;
5757
}

src/solvers/flattening/boolbv_extractbits.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr)
4040

4141
const std::size_t offset = numeric_cast_v<std::size_t>(index_as_int);
4242

43-
bvt result_bv(src_bv.begin() + offset, src_bv.begin() + offset + bv_width);
43+
bvt result_bv(
44+
src_bv.begin() + static_cast<std::ptrdiff_t>(offset),
45+
src_bv.begin() + static_cast<std::ptrdiff_t>(offset + bv_width));
4446

4547
return result_bv;
4648
}

src/solvers/flattening/boolbv_mult.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ bvt boolbvt::convert_mult(const mult_exprt &expr)
5050
bv=bv_utils.signed_multiplier(bv, op);
5151

5252
// cut it down again
53-
bv.erase(bv.begin(), bv.begin()+fraction_bits);
53+
bv.erase(
54+
bv.begin(), bv.begin() + static_cast<std::ptrdiff_t>(fraction_bits));
5455
}
5556

5657
return bv;

src/solvers/flattening/boolbv_typecast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ bool boolbvt::type_conversion(
7777
{
7878
// recursively do both halfs
7979
bvt lower, upper, lower_res, upper_res;
80-
lower.assign(src.begin(), src.begin() + src.size() / 2);
81-
upper.assign(src.begin() + src.size() / 2, src.end());
80+
lower.assign(src.begin(), src.begin() + static_cast<std::ptrdiff_t>(src.size() / 2));
81+
upper.assign(src.begin() + static_cast<std::ptrdiff_t>(src.size() / 2), src.end());
8282
type_conversion(
8383
to_complex_type(src_type).subtype(),
8484
lower,

src/solvers/flattening/boolbv_unary_minus.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ bvt boolbvt::convert_unary_minus(const unary_minus_exprt &expr)
5151
{
5252
bvt tmp_op;
5353

54-
const auto sub_it = std::next(op_bv.begin(), sub_idx);
54+
const auto sub_it =
55+
std::next(op_bv.begin(), static_cast<std::ptrdiff_t>(sub_idx));
5556
std::copy_n(sub_it, sub_width, std::back_inserter(tmp_op));
5657

5758
if(subtype.id() == ID_floatbv)

src/solvers/flattening/bv_utils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ bvt bv_utilst::extract(const bvt &a, std::size_t first, std::size_t last)
4848
bvt result=a;
4949
result.resize(last+1);
5050
if(first!=0)
51-
result.erase(result.begin(), result.begin()+first);
51+
result.erase(
52+
result.begin(), result.begin() + static_cast<std::ptrdiff_t>(first));
5253

5354
POSTCONDITION(result.size() == last - first + 1);
5455
return result;
@@ -60,7 +61,9 @@ bvt bv_utilst::extract_msb(const bvt &a, std::size_t n)
6061
PRECONDITION(n <= a.size());
6162

6263
bvt result=a;
63-
result.erase(result.begin(), result.begin()+(result.size()-n));
64+
result.erase(
65+
result.begin(),
66+
result.begin() + static_cast<std::ptrdiff_t>(result.size() - n));
6467

6568
POSTCONDITION(result.size() == n);
6669
return result;

src/solvers/floatbv/float_utils.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ bvt float_utilst::limit_distance(
393393
std::size_t nb_bits = address_bits(limit);
394394

395395
bvt upper_bits=dist;
396-
upper_bits.erase(upper_bits.begin(), upper_bits.begin()+nb_bits);
396+
upper_bits.erase(
397+
upper_bits.begin(),
398+
upper_bits.begin() + static_cast<std::ptrdiff_t>(nb_bits));
397399
literalt or_upper_bits=prop.lor(upper_bits);
398400

399401
bvt lower_bits=dist;
@@ -713,7 +715,8 @@ literalt float_utilst::exponent_all_ones(const bvt &src)
713715
bvt exponent=src;
714716

715717
// removes the fractional part
716-
exponent.erase(exponent.begin(), exponent.begin()+spec.f);
718+
exponent.erase(
719+
exponent.begin(), exponent.begin() + static_cast<std::ptrdiff_t>(spec.f));
717720

718721
// removes the sign
719722
exponent.resize(spec.e);
@@ -726,7 +729,8 @@ literalt float_utilst::exponent_all_zeros(const bvt &src)
726729
bvt exponent=src;
727730

728731
// removes the fractional part
729-
exponent.erase(exponent.begin(), exponent.begin()+spec.f);
732+
exponent.erase(
733+
exponent.begin(), exponent.begin() + static_cast<std::ptrdiff_t>(spec.f));
730734

731735
// removes the sign
732736
exponent.resize(spec.e);

0 commit comments

Comments
 (0)