Skip to content
Permalink
Browse files

Silence cppcheck warning

  • Loading branch information...
kimwalisch committed Dec 2, 2018
1 parent dc11728 commit 396c31d86c4e5f760c8ca1d6d5e2bb12480cb05c
Showing with 12 additions and 10 deletions.
  1. +1 −1 .travis.yml
  2. +11 −9 test/move_primesieve_iterator.cpp
@@ -71,4 +71,4 @@ script:
- valgrind --error-exitcode=1 ./nth_prime 500000000
# 7) Test using cppcheck
- rm -rf build
- cppcheck . -q --error-exitcode=1 -iexamples/cpp/prev_prime.cpp -iexamples/cpp/primesieve_iterator.cpp -itest/next_prime1.cpp -itest/prev_prime1.cpp
- cppcheck . -q --error-exitcode=1 -iexamples/cpp/prev_prime.cpp -iexamples/cpp/primesieve_iterator.cpp -itest/move_primesieve_iterator.cpp -itest/next_prime1.cpp -itest/prev_prime1.cpp
@@ -47,19 +47,21 @@ int main()

// test move assignment operator ///////////////////////////////////

prime = it2.prev_prime();
// moved from objects can be reused
// but they need to be reset
it.skipto(0);
prime = it.next_prime();
sum = 0;

// use 2nd iterator for primes > 6e8
for (; prime > 600000000ull; prime = it2.prev_prime())
// use 1st iterator up to 6e8
for (; prime < 600000000ull; prime = it.next_prime())
sum += prime;

// move assignment operator
primesieve::iterator it3;
it3 = std::move(it2);
it2 = std::move(it);

// use 3rd iterator for primes <= 6e8
for (; prime > 0; prime = it3.prev_prime())
// use 2nd iterator up to 1e9
for (; prime < 1000000000ull; prime = it2.next_prime())
sum += prime;

cout << "Sum of the primes below 10^9 = " << sum;
@@ -73,8 +75,8 @@ int main()
cout << "1st prime < 1000 = " << prime;
check(prime == 997);

it3.skipto(5);
vect.emplace_back(std::move(it3));
it2.skipto(5);
vect.emplace_back(std::move(it2));
prime = vect.back().next_prime();
cout << "1st prime > 5 = " << prime;
check(prime == 7);

0 comments on commit 396c31d

Please sign in to comment.
You can’t perform that action at this time.