fixes for complaints by cppcheck

This commit is contained in:
Hans Dembinski 2018-12-04 00:12:34 +01:00
parent 1e0dcc72fb
commit ab8201eca1
7 changed files with 22 additions and 17 deletions

View File

@ -32,7 +32,6 @@ adaptive_storage_type prepare(std::size_t n) {
template <typename T> template <typename T>
void serialization_impl() { void serialization_impl() {
const auto a = prepare(1, T(1)); const auto a = prepare(1, T(1));
std::ostringstream os;
std::string buf; std::string buf;
{ {
std::ostringstream os; std::ostringstream os;
@ -53,13 +52,12 @@ void serialization_impl() {
template <> template <>
void serialization_impl<void>() { void serialization_impl<void>() {
const auto a = prepare<void>(1); const auto a = prepare<void>(1);
std::ostringstream os;
std::string buf; std::string buf;
{ {
std::ostringstream os2; std::ostringstream os;
boost::archive::text_oarchive oa(os2); boost::archive::text_oarchive oa(os);
oa << a; oa << a;
buf = os2.str(); buf = os.str();
} }
adaptive_storage_type b; adaptive_storage_type b;
BOOST_TEST(!(a == b)); BOOST_TEST(!(a == b));

View File

@ -43,7 +43,6 @@ void copy_impl() {
BOOST_TEST(a == b); BOOST_TEST(a == b);
a(0); a(0);
BOOST_TEST(!(a == b)); BOOST_TEST(!(a == b));
a = b;
a = prepare<T>(2); a = prepare<T>(2);
BOOST_TEST(!(a == b)); BOOST_TEST(!(a == b));
a = b; a = b;
@ -129,7 +128,7 @@ void convert_array_storage_impl() {
s.reset(1); s.reset(1);
s(0); s(0);
auto a = aref; auto a(aref);
a = s; a = s;
BOOST_TEST_EQ(a[0], 1.0); BOOST_TEST_EQ(a[0], 1.0);
BOOST_TEST(a == s); BOOST_TEST(a == s);
@ -152,11 +151,11 @@ void convert_array_storage_impl() {
t.reset(1); t.reset(1);
t(0); t(0);
while (t[0] < 1e20) t.add(0, t[0]); while (t[0] < 1e20) t.add(0, t[0]);
auto d = aref; auto d(aref);
d = t; d = t;
BOOST_TEST(d == t); BOOST_TEST(d == t);
auto e = aref; auto e(aref);
e = s; e = s;
BOOST_TEST_EQ(e[0], 1.0); BOOST_TEST_EQ(e[0], 1.0);
BOOST_TEST(e == s); BOOST_TEST(e == s);
@ -192,14 +191,14 @@ void convert_array_storage_impl<void>() {
s.reset(1); s.reset(1);
s(0); s(0);
auto a = aref; auto a(aref);
a = s; a = s;
BOOST_TEST_EQ(a[0], 1.0); BOOST_TEST_EQ(a[0], 1.0);
BOOST_TEST(a == s); BOOST_TEST(a == s);
a(0); a(0);
BOOST_TEST(!(a == s)); BOOST_TEST(!(a == s));
auto c = aref; auto c(aref);
c.add(0, s[0]); c.add(0, s[0]);
BOOST_TEST_EQ(c[0], 1.0); BOOST_TEST_EQ(c[0], 1.0);
BOOST_TEST(c == s); BOOST_TEST(c == s);

View File

@ -38,7 +38,6 @@ int main() {
BOOST_TEST_EQ(a, b); BOOST_TEST_EQ(a, b);
axis::category<std::string> c = std::move(b); axis::category<std::string> c = std::move(b);
BOOST_TEST_EQ(c, a); BOOST_TEST_EQ(c, a);
BOOST_TEST_NE(b, a);
axis::category<std::string> d; axis::category<std::string> d;
BOOST_TEST_NE(c, d); BOOST_TEST_NE(c, d);
d = std::move(c); d = std::move(c);

View File

@ -33,7 +33,6 @@ int main() {
BOOST_TEST_EQ(a, b); BOOST_TEST_EQ(a, b);
axis::variable<> c = std::move(b); axis::variable<> c = std::move(b);
BOOST_TEST_EQ(c, a); BOOST_TEST_EQ(c, a);
BOOST_TEST_NE(b, a);
axis::variable<> d; axis::variable<> d;
BOOST_TEST_NE(c, d); BOOST_TEST_NE(c, d);
d = std::move(c); d = std::move(c);

View File

@ -103,7 +103,7 @@ int main() {
axis::variant<axis::regular<>> b(std::move(a)); axis::variant<axis::regular<>> b(std::move(a));
BOOST_TEST_EQ(b, r); BOOST_TEST_EQ(b, r);
axis::variant<axis::regular<>> c; axis::variant<axis::regular<>> c;
BOOST_TEST_NOT(a == c); BOOST_TEST_NE(c, b);
c = std::move(b); c = std::move(b);
BOOST_TEST(c == r); BOOST_TEST(c == r);
} }

View File

@ -24,7 +24,6 @@ void test_serialization() {
a.reset(3); a.reset(3);
a(0); a(0);
a(2); a(2);
std::ostringstream os;
std::string buf; std::string buf;
{ {
std::ostringstream os; std::ostringstream os;

View File

@ -36,15 +36,26 @@ struct tracing_allocator {
tracing_allocator(tracing_allocator_db& x) noexcept : db(&x) {} tracing_allocator(tracing_allocator_db& x) noexcept : db(&x) {}
template <class U> template <class U>
tracing_allocator(const tracing_allocator<U>& a) noexcept : db(a.db) {} tracing_allocator(const tracing_allocator<U>& a) noexcept : db(a.db) {}
template <class U>
tracing_allocator& operator=(const tracing_allocator<U>& a) noexcept {
db = a.db;
return *this;
}
~tracing_allocator() noexcept {} ~tracing_allocator() noexcept {}
T* allocate(std::size_t n) { T* allocate(std::size_t n) {
if (db) { db->at<T>().first += n; db->sum.first += n; } if (db) {
db->at<T>().first += n;
db->sum.first += n;
}
return static_cast<T*>(::operator new(n * sizeof(T))); return static_cast<T*>(::operator new(n * sizeof(T)));
} }
void deallocate(T* p, std::size_t n) { void deallocate(T* p, std::size_t n) {
if (db) { db->at<T>().second += n; db->sum.second += n; } if (db) {
db->at<T>().second += n;
db->sum.second += n;
}
::operator delete((void*)p); ::operator delete((void*)p);
} }
}; };