From 8b429bac9a55acbfbc6c4e7ca7ec38eebfb7e593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Me=C3=9Fmer?= Date: Sat, 17 Oct 2015 20:15:20 +0200 Subject: [PATCH] Fix warnings from -Weffc++ --- biicode.conf | 2 +- io/Console.h | 1 + io/pipestream.h | 7 ++++++- random/RandomDataBuffer.h | 14 ++++++++------ random/ThreadsafeRandomDataBuffer.h | 2 +- test/EitherTest.cpp | 2 ++ test/logging/testutils/LoggingTest.h | 2 ++ test/pointer/cast_test.cpp | 5 +++++ test/pointer/optional_ownership_ptr_test.cpp | 4 ++++ 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/biicode.conf b/biicode.conf index f85420a2..ab437e2d 100644 --- a/biicode.conf +++ b/biicode.conf @@ -5,7 +5,7 @@ google/gmock: 4 google/gtest: 11 messmer/cmake: 3 - messmer/spdlog: 0 + messmer/spdlog: 1 [parent] messmer/cpp-utils: 4 diff --git a/io/Console.h b/io/Console.h index 47f69440..5c88b891 100644 --- a/io/Console.h +++ b/io/Console.h @@ -11,6 +11,7 @@ namespace cpputils { class Console { public: + virtual ~Console() {} virtual unsigned int ask(const std::string &question, const std::vector &options) = 0; virtual bool askYesNo(const std::string &question) = 0; virtual void print(const std::string &output) = 0; diff --git a/io/pipestream.h b/io/pipestream.h index 96d07af4..101bb601 100644 --- a/io/pipestream.h +++ b/io/pipestream.h @@ -47,6 +47,7 @@ #include #include #include +#include "../macros.h" //TODO Add test cases @@ -67,7 +68,9 @@ namespace cpputils { public: pipestream(string_size_t out_size = 16, string_size_t in_size = 64) - : d_out(std::max(string_size_t(1), out_size), ' ') + : d_mutex() + , d_condition() + , d_out(std::max(string_size_t(1), out_size), ' ') , d_in(std::max(string_size_t(1), in_size), ' ') , d_tmp(std::max(string_size_t(1), in_size), ' ') , d_current(&this->d_tmp[0]) @@ -144,6 +147,8 @@ namespace cpputils { } return traits_type::eof(); } + + DISALLOW_COPY_AND_ASSIGN(pipestream); }; } diff --git a/random/RandomDataBuffer.h b/random/RandomDataBuffer.h index 0947d3e3..09fa08b9 100644 --- a/random/RandomDataBuffer.h +++ b/random/RandomDataBuffer.h @@ -24,7 +24,7 @@ namespace cpputils { DISALLOW_COPY_AND_ASSIGN(RandomDataBuffer); }; - inline RandomDataBuffer::RandomDataBuffer() : _data(0) { + inline RandomDataBuffer::RandomDataBuffer() : _usedUntil(0), _data(0) { } inline size_t RandomDataBuffer::size() const { @@ -37,12 +37,14 @@ namespace cpputils { _usedUntil += numBytes; } - inline void RandomDataBuffer::add(Data data) { + inline void RandomDataBuffer::add(Data newData) { // Concatenate old and new random data - Data newdata(_data.size() + data.size()); - std::memcpy(newdata.data(), _data.data(), _data.size()); - std::memcpy(newdata.dataOffset(_data.size()), data.data(), data.size()); - _data = std::move(newdata); + size_t oldSize = size(); + Data combined(oldSize + newData.size()); + get(combined.data(), oldSize); + std::memcpy(combined.dataOffset(oldSize), newData.data(), newData.size()); + _data = std::move(combined); + _usedUntil = 0; } } diff --git a/random/ThreadsafeRandomDataBuffer.h b/random/ThreadsafeRandomDataBuffer.h index f8b6637c..daa36d36 100644 --- a/random/ThreadsafeRandomDataBuffer.h +++ b/random/ThreadsafeRandomDataBuffer.h @@ -35,7 +35,7 @@ namespace cpputils { DISALLOW_COPY_AND_ASSIGN(ThreadsafeRandomDataBuffer); }; - inline ThreadsafeRandomDataBuffer::ThreadsafeRandomDataBuffer() { + inline ThreadsafeRandomDataBuffer::ThreadsafeRandomDataBuffer(): _buffer(), _mutex(), _dataAddedCv(), _dataGottenCv() { } inline size_t ThreadsafeRandomDataBuffer::size() const { diff --git a/test/EitherTest.cpp b/test/EitherTest.cpp index 62e3ef17..b9a23324 100644 --- a/test/EitherTest.cpp +++ b/test/EitherTest.cpp @@ -380,6 +380,8 @@ public: private: const DestructorCallback *_destructorCallback; + + ClassWithDestructorCallback &operator=(const ClassWithDestructorCallback &rhs) = delete; }; class OnlyMoveableClassWithDestructorCallback { public: diff --git a/test/logging/testutils/LoggingTest.h b/test/logging/testutils/LoggingTest.h index e64ec9b0..8c45aa59 100644 --- a/test/logging/testutils/LoggingTest.h +++ b/test/logging/testutils/LoggingTest.h @@ -33,6 +33,8 @@ private: class LoggingTest: public ::testing::Test { public: + LoggingTest(): mockLogger() {} + std::string captureStderr(std::function func) { testing::internal::CaptureStderr(); func(); diff --git a/test/pointer/cast_test.cpp b/test/pointer/cast_test.cpp index 5bc6e15b..ce9259aa 100644 --- a/test/pointer/cast_test.cpp +++ b/test/pointer/cast_test.cpp @@ -36,6 +36,7 @@ public: private: const DestructorCallback *_destructorCallback; + DISALLOW_COPY_AND_ASSIGN(Child); }; class Child2 : public Parent {}; @@ -129,6 +130,8 @@ TEST(UniquePtr_DynamicPointerMoveTest, ChildToParentCast) { class UniqueRef_DynamicPointerMoveDestructorTest: public ::testing::Test { public: + UniqueRef_DynamicPointerMoveDestructorTest(): childDestructorCallback() {} + DestructorCallback childDestructorCallback; unique_ref createChild() { return make_unique_ref(&childDestructorCallback); @@ -140,6 +143,8 @@ public: class UniquePtr_DynamicPointerMoveDestructorTest: public ::testing::Test { public: + UniquePtr_DynamicPointerMoveDestructorTest(): childDestructorCallback() {} + DestructorCallback childDestructorCallback; unique_ptr createChild() { return make_unique(&childDestructorCallback); diff --git a/test/pointer/optional_ownership_ptr_test.cpp b/test/pointer/optional_ownership_ptr_test.cpp index 43889186..05a7e217 100644 --- a/test/pointer/optional_ownership_ptr_test.cpp +++ b/test/pointer/optional_ownership_ptr_test.cpp @@ -14,6 +14,7 @@ public: virtual ~TestObject() { _destructorListener(); } + private: function _destructorListener; }; @@ -42,10 +43,13 @@ public: private: bool _isDestructed; TestObject *_testObject; + DISALLOW_COPY_AND_ASSIGN(TestObjectHolder); }; class OptionalOwnershipPointerTest: public Test { public: + OptionalOwnershipPointerTest(): obj(), obj2() {} + TestObjectHolder obj; TestObjectHolder obj2; };