Introduce clang-tidy and fix corresponding warnings

This commit is contained in:
Sebastian Messmer 2017-10-27 04:02:51 +01:00
parent 5dfaf948b7
commit 76e7f7da72
20 changed files with 107 additions and 55 deletions

27
.clang-tidy Normal file
View File

@ -0,0 +1,27 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,misc-use-after-move'
WarningsAsErrors: ''
HeaderFilterRegex: '/src/|/test/'
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

View File

@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# note: for clang-tidy, we need cmake 3.6, or (if the return code should be handled correctly, e.g. on CI), we need 3.8.
project(cryfs) project(cryfs)
include(utils.cmake) include(utils.cmake)

View File

@ -28,7 +28,7 @@ BlobOnBlocks::BlobOnBlocks(unique_ref<DataTreeRef> datatree)
} }
BlobOnBlocks::~BlobOnBlocks() { BlobOnBlocks::~BlobOnBlocks() {
} } // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
uint64_t BlobOnBlocks::size() const { uint64_t BlobOnBlocks::size() const {
if (_sizeCache == boost::none) { if (_sizeCache == boost::none) {

View File

@ -40,10 +40,12 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
if (condition(*currentNode)) { if (condition(*currentNode)) {
result = std::move(currentNode); result = std::move(currentNode);
} }
ASSERT(lastChild != none || static_cast<int>(i) == rootNode->depth()-1, "Couldn't get last child as inner node but we're not deep enough yet for the last child to be a leaf"); if (lastChild == none) {
if (lastChild != none) { // lastChild is a leaf
currentNode = cpputils::WithOwnership(std::move(*lastChild)); ASSERT(static_cast<int>(i) == rootNode->depth()-1, "Couldn't get last child as inner node but we're not deep enough yet for the last child to be a leaf");
break;
} }
currentNode = cpputils::WithOwnership(std::move(*lastChild));
} }
return result; return result;

View File

@ -33,7 +33,7 @@ optional<unique_ref<DataTreeRef>> ParallelAccessDataTreeStore::load(const blocks
unique_ref<DataTreeRef> ParallelAccessDataTreeStore::createNewTree() { unique_ref<DataTreeRef> ParallelAccessDataTreeStore::createNewTree() {
auto dataTree = _dataTreeStore->createNewTree(); auto dataTree = _dataTreeStore->createNewTree();
BlockId blockId = dataTree->blockId(); BlockId blockId = dataTree->blockId();
return _parallelAccessStore.add(blockId, std::move(dataTree)); return _parallelAccessStore.add(blockId, std::move(dataTree)); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
} }
void ParallelAccessDataTreeStore::remove(unique_ref<DataTreeRef> tree) { void ParallelAccessDataTreeStore::remove(unique_ref<DataTreeRef> tree) {

View File

@ -57,7 +57,7 @@ unique_ref<Block> ParallelAccessBlockStore::overwrite(const BlockId &blockId, Da
auto onAdd = [this, blockId, &data] { auto onAdd = [this, blockId, &data] {
return _baseBlockStore->overwrite(blockId, data.copy()); // TODO Without copy? return _baseBlockStore->overwrite(blockId, data.copy()); // TODO Without copy?
}; };
return _parallelAccessStore.loadOrAdd(blockId, onExists, onAdd); return _parallelAccessStore.loadOrAdd(blockId, onExists, onAdd); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
} }
void ParallelAccessBlockStore::remove(unique_ref<Block> block) { void ParallelAccessBlockStore::remove(unique_ref<Block> block) {

View File

@ -289,7 +289,7 @@ void CryDevice::RemoveBlob(const blockstore::BlockId &blockId) {
BlockId CryDevice::GetOrCreateRootBlobId(CryConfigFile *configFile) { BlockId CryDevice::GetOrCreateRootBlobId(CryConfigFile *configFile) {
string root_blockId = configFile->config()->RootBlob(); string root_blockId = configFile->config()->RootBlob();
if (root_blockId == "") { if (root_blockId == "") { // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
auto new_blockId = CreateRootBlobAndReturnId(); auto new_blockId = CreateRootBlobAndReturnId();
configFile->config()->SetRootBlob(new_blockId.ToString()); configFile->config()->SetRootBlob(new_blockId.ToString());
configFile->save(); configFile->save();

View File

@ -72,7 +72,7 @@ unique_ref<DirBlobRef> CryDir::LoadBlob() const {
unique_ref<vector<fspp::Dir::Entry>> CryDir::children() { unique_ref<vector<fspp::Dir::Entry>> CryDir::children() {
device()->callFsActionCallbacks(); device()->callFsActionCallbacks();
if (!isRootDir()) { if (!isRootDir()) { // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
//TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function) //TODO Instead of doing nothing when we're the root directory, handle timestamps in the root dir correctly (and delete isRootDir() function)
parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME);
} }

View File

@ -45,7 +45,7 @@ unique_ref<fspp::OpenFile> CryFile::open(int flags) {
void CryFile::truncate(off_t size) { void CryFile::truncate(off_t size) {
device()->callFsActionCallbacks(); device()->callFsActionCallbacks();
auto blob = LoadBlob(); auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
blob->resize(size); blob->resize(size);
parent()->updateModificationTimestampForChild(blockId()); parent()->updateModificationTimestampForChild(blockId());
} }

View File

@ -155,7 +155,7 @@ const CryDevice *CryNode::device() const {
unique_ref<FsBlobRef> CryNode::LoadBlob() const { unique_ref<FsBlobRef> CryNode::LoadBlob() const {
auto blob = _device->LoadBlob(_blockId); auto blob = _device->LoadBlob(_blockId);
ASSERT(_parent == none || blob->parentPointer() == (*_parent)->blockId(), "Blob has wrong parent pointer."); ASSERT(_parent == none || blob->parentPointer() == (*_parent)->blockId(), "Blob has wrong parent pointer.");
return blob; return blob; // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
} }
const blockstore::BlockId &CryNode::blockId() const { const blockstore::BlockId &CryNode::blockId() const {

View File

@ -25,7 +25,7 @@ CryOpenFile::CryOpenFile(const CryDevice *device, shared_ptr<DirBlobRef> parent,
CryOpenFile::~CryOpenFile() { CryOpenFile::~CryOpenFile() {
//TODO //TODO
} } // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
void CryOpenFile::flush() { void CryOpenFile::flush() {
_device->callFsActionCallbacks(); _device->callFsActionCallbacks();

View File

@ -48,7 +48,7 @@ fspp::Dir::EntryType CrySymlink::getType() const {
bf::path CrySymlink::target() { bf::path CrySymlink::target() {
device()->callFsActionCallbacks(); device()->callFsActionCallbacks();
parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME);
auto blob = LoadBlob(); auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
return blob->target(); return blob->target();
} }

View File

@ -18,7 +18,7 @@ namespace cryfs {
namespace parallelaccessfsblobstore { namespace parallelaccessfsblobstore {
optional<unique_ref<FsBlobRef>> ParallelAccessFsBlobStore::load(const BlockId &blockId) { optional<unique_ref<FsBlobRef>> ParallelAccessFsBlobStore::load(const BlockId &blockId) {
return _parallelAccessStore.load(blockId, [this] (cachingfsblobstore::FsBlobRef *blob) { return _parallelAccessStore.load(blockId, [this] (cachingfsblobstore::FsBlobRef *blob) { // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
cachingfsblobstore::FileBlobRef *fileBlob = dynamic_cast<cachingfsblobstore::FileBlobRef*>(blob); cachingfsblobstore::FileBlobRef *fileBlob = dynamic_cast<cachingfsblobstore::FileBlobRef*>(blob);
if (fileBlob != nullptr) { if (fileBlob != nullptr) {
return unique_ref<FsBlobRef>(make_unique_ref<FileBlobRef>(fileBlob)); return unique_ref<FsBlobRef>(make_unique_ref<FileBlobRef>(fileBlob));

View File

@ -210,7 +210,7 @@ void ParallelAccessStore<Resource, ResourceRef, Key>::remove(const Key &key, cpp
template<class Resource, class ResourceRef, class Key> template<class Resource, class ResourceRef, class Key>
std::future<cpputils::unique_ref<Resource>> ParallelAccessStore<Resource, ResourceRef, Key>::_resourceToRemoveFuture(const Key &key) { std::future<cpputils::unique_ref<Resource>> ParallelAccessStore<Resource, ResourceRef, Key>::_resourceToRemoveFuture(const Key &key) {
std::lock_guard <std::mutex> lock(_mutex); // TODO Lock needed for _resourcesToRemove? std::lock_guard <std::mutex> lock(_mutex); // TODO Lock needed for _resourcesToRemove?
auto insertResult = _resourcesToRemove.emplace(key, std::promise < cpputils::unique_ref < Resource >> ()); auto insertResult = _resourcesToRemove.emplace(key, std::promise<cpputils::unique_ref<Resource>>());
ASSERT(true == insertResult.second, "Inserting failed"); ASSERT(true == insertResult.second, "Inserting failed");
return insertResult.first->second.get_future(); return insertResult.first->second.get_future();
}; };

View File

@ -49,22 +49,22 @@ public:
void EXPECT_LEFT_IS(const Expected &expected, either<Left, Right> &value) { void EXPECT_LEFT_IS(const Expected &expected, either<Left, Right> &value) {
EXPECT_IS_LEFT(value); EXPECT_IS_LEFT(value);
EXPECT_EQ(expected, value.left()); EXPECT_EQ(expected, value.left());
EXPECT_EQ(expected, value.left_opt().get()); EXPECT_EQ(expected, value.left_opt().value());
EXPECT_EQ(boost::none, value.right_opt()); EXPECT_EQ(boost::none, value.right_opt());
const either<Left, Right> &const_value = value; const either<Left, Right> &const_value = value;
EXPECT_EQ(expected, const_value.left()); EXPECT_EQ(expected, const_value.left());
EXPECT_EQ(expected, const_value.left_opt().get()); EXPECT_EQ(expected, const_value.left_opt().value());
EXPECT_EQ(boost::none, const_value.right_opt()); EXPECT_EQ(boost::none, const_value.right_opt());
} }
template<class Left, class Right, class Expected> template<class Left, class Right, class Expected>
void EXPECT_RIGHT_IS(const Expected &expected, either<Left, Right> &value) { void EXPECT_RIGHT_IS(const Expected &expected, either<Left, Right> &value) {
EXPECT_IS_RIGHT(value); EXPECT_IS_RIGHT(value);
EXPECT_EQ(expected, value.right()); EXPECT_EQ(expected, value.right());
EXPECT_EQ(expected, value.right_opt().get()); EXPECT_EQ(expected, value.right_opt().value());
EXPECT_EQ(boost::none, value.left_opt()); EXPECT_EQ(boost::none, value.left_opt());
const either<Left, Right> &const_value = value; const either<Left, Right> &const_value = value;
EXPECT_EQ(expected, const_value.right()); EXPECT_EQ(expected, const_value.right());
EXPECT_EQ(expected, const_value.right_opt().get()); EXPECT_EQ(expected, const_value.right_opt().value());
EXPECT_EQ(boost::none, const_value.left_opt()); EXPECT_EQ(boost::none, const_value.left_opt());
} }
}; };
@ -244,13 +244,13 @@ TEST_F(EitherTest, ModifyRight) {
TEST_F(EitherTest, ModifyLeftOpt) { TEST_F(EitherTest, ModifyLeftOpt) {
either<string, int> val = string("mystring1"); either<string, int> val = string("mystring1");
val.left_opt().get() = "mystring2"; val.left_opt().value() = "mystring2";
EXPECT_LEFT_IS("mystring2", val); EXPECT_LEFT_IS("mystring2", val);
} }
TEST_F(EitherTest, ModifyRightOpt) { TEST_F(EitherTest, ModifyRightOpt) {
either<int, string> val = string("mystring1"); either<int, string> val = string("mystring1");
val.right_opt().get() = "mystring2"; val.right_opt().value() = "mystring2";
EXPECT_RIGHT_IS("mystring2", val); EXPECT_RIGHT_IS("mystring2", val);
} }

View File

@ -141,8 +141,8 @@ TEST_F(DataTest, MoveConstructor) {
Data original = DataFixture::generate(1024); Data original = DataFixture::generate(1024);
Data copy(std::move(original)); Data copy(std::move(original));
EXPECT_EQ(DataFixture::generate(1024), copy); EXPECT_EQ(DataFixture::generate(1024), copy);
EXPECT_EQ(nullptr, original.data()); EXPECT_EQ(nullptr, original.data()); // NOLINT (intentional use-after-move)
EXPECT_EQ(0u, original.size()); EXPECT_EQ(0u, original.size()); // NOLINT (intentional use-after-move)
} }
TEST_F(DataTest, MoveAssignment) { TEST_F(DataTest, MoveAssignment) {
@ -150,8 +150,8 @@ TEST_F(DataTest, MoveAssignment) {
Data copy(0); Data copy(0);
copy = std::move(original); copy = std::move(original);
EXPECT_EQ(DataFixture::generate(1024), copy); EXPECT_EQ(DataFixture::generate(1024), copy);
EXPECT_EQ(nullptr, original.data()); EXPECT_EQ(nullptr, original.data()); // NOLINT (intentional use-after-move)
EXPECT_EQ(0u, original.size()); EXPECT_EQ(0u, original.size()); // NOLINT (intentional use-after-move)
} }
TEST_F(DataTest, Equality) { TEST_F(DataTest, Equality) {

View File

@ -190,21 +190,21 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigning_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
unique_ref<SomeClass> obj2 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj2 = make_unique_ref<SomeClass>();
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClass_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClass_thenPointsToSameObject) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
unique_ref<SomeBaseClass> base = make_unique_ref<SomeBaseClass>(10); unique_ref<SomeBaseClass> base = make_unique_ref<SomeBaseClass>(10);
base = std::move(child); base = std::move(child);
EXPECT_EQ(3, base->v); EXPECT_EQ(3, base->v); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClass_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClass_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
unique_ref<SomeBaseClass> obj2 = make_unique_ref<SomeBaseClass>(10); unique_ref<SomeBaseClass> obj2 = make_unique_ref<SomeBaseClass>(10);
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToUniquePtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToUniquePtr_thenPointsToSameObject) {
@ -219,7 +219,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToUniquePtr_thenOldInstanc
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::unique_ptr<SomeClass> obj2 = std::make_unique<SomeClass>(); std::unique_ptr<SomeClass> obj2 = std::make_unique<SomeClass>();
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassUniquePtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassUniquePtr_thenPointsToSameObject) {
@ -233,7 +233,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassUniquePtr_thenO
unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
std::unique_ptr<SomeBaseClass> obj2 = std::make_unique<SomeBaseClass>(10); std::unique_ptr<SomeBaseClass> obj2 = std::make_unique<SomeBaseClass>(10);
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToSharedPtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToSharedPtr_thenPointsToSameObject) {
@ -248,7 +248,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToSharedPtr_thenOldInstanc
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::shared_ptr<SomeClass> obj2 = std::make_shared<SomeClass>(); std::shared_ptr<SomeClass> obj2 = std::make_shared<SomeClass>();
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassSharedPtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassSharedPtr_thenPointsToSameObject) {
@ -262,7 +262,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassSharedPtr_thenO
unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
std::shared_ptr<SomeBaseClass> obj2 = std::make_shared<SomeBaseClass>(10); std::shared_ptr<SomeBaseClass> obj2 = std::make_shared<SomeBaseClass>(10);
obj2 = std::move(obj1); obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenPointsToSameObject) {
@ -275,7 +275,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenPointsToSameObject
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
unique_ref<SomeClass> obj2 = std::move(obj1); unique_ref<SomeClass> obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenPointsToSameObject) {
@ -287,7 +287,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
unique_ref<SomeBaseClass> base = std::move(child); unique_ref<SomeBaseClass> base = std::move(child);
EXPECT_FALSE(child.is_valid()); EXPECT_FALSE(child.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenPointsToSameObject) {
@ -300,7 +300,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::unique_ptr<SomeClass> obj2 = std::move(obj1); std::unique_ptr<SomeClass> obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenPointsToSameObject) {
@ -312,7 +312,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_th
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
std::unique_ptr<SomeBaseClass> base = std::move(child); std::unique_ptr<SomeBaseClass> base = std::move(child);
EXPECT_FALSE(child.is_valid()); EXPECT_FALSE(child.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenPointsToSameObject) {
@ -325,7 +325,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>(); unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::shared_ptr<SomeClass> obj2 = std::move(obj1); std::shared_ptr<SomeClass> obj2 = std::move(obj1);
EXPECT_FALSE(obj1.is_valid()); EXPECT_FALSE(obj1.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenPointsToSameObject) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenPointsToSameObject) {
@ -337,7 +337,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_th
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenOldInstanceInvalid) { TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3); unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
std::shared_ptr<SomeBaseClass> base = std::move(child); std::shared_ptr<SomeBaseClass> base = std::move(child);
EXPECT_FALSE(child.is_valid()); EXPECT_FALSE(child.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, Swap) { TEST_F(UniqueRefTest, Swap) {
@ -388,7 +388,7 @@ TEST_F(UniqueRefTest, SwapFromRValue) {
SomeClass *obj1ptr = obj1.get(); SomeClass *obj1ptr = obj1.get();
SomeClass *obj2ptr = obj2.get(); SomeClass *obj2ptr = obj2.get();
std::swap(std::move(obj1), obj2); std::swap(std::move(obj1), obj2);
EXPECT_EQ(obj2ptr, obj1.get()); EXPECT_EQ(obj2ptr, obj1.get()); // NOLINT (intentional use-after-move)
EXPECT_EQ(obj1ptr, obj2.get()); EXPECT_EQ(obj1ptr, obj2.get());
} }
@ -399,7 +399,7 @@ TEST_F(UniqueRefTest, SwapWithRValue) {
SomeClass *obj2ptr = obj2.get(); SomeClass *obj2ptr = obj2.get();
std::swap(obj1, std::move(obj2)); std::swap(obj1, std::move(obj2));
EXPECT_EQ(obj2ptr, obj1.get()); EXPECT_EQ(obj2ptr, obj1.get());
EXPECT_EQ(obj1ptr, obj2.get()); EXPECT_EQ(obj1ptr, obj2.get()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, CanBePutInContainer_Primitive) { TEST_F(UniqueRefTest, CanBePutInContainer_Primitive) {
@ -503,8 +503,8 @@ TEST_F(UniqueRefTest, Equality_Nullptr) {
unique_ref<int> var2 = make_unique_ref<int>(4); unique_ref<int> var2 = make_unique_ref<int>(4);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_TRUE(var1 == var2); EXPECT_TRUE(var1 == var2); // NOLINT (intentional use-after-move)
EXPECT_FALSE(var1 != var2); EXPECT_FALSE(var1 != var2); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, Nonequality) { TEST_F(UniqueRefTest, Nonequality) {
@ -518,16 +518,16 @@ TEST_F(UniqueRefTest, Nonequality_NullptrLeft) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
EXPECT_TRUE(var1 != var2); EXPECT_TRUE(var1 != var2); // NOLINT (intentional use-after-move)
EXPECT_FALSE(var1 == var2); EXPECT_FALSE(var1 == var2); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, Nonequality_NullptrRight) { TEST_F(UniqueRefTest, Nonequality_NullptrRight) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_TRUE(var1 != var2); EXPECT_TRUE(var1 != var2); // NOLINT (intentional use-after-move)
EXPECT_FALSE(var1 == var2); EXPECT_FALSE(var1 == var2); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, HashIsDifferent) { TEST_F(UniqueRefTest, HashIsDifferent) {
@ -540,14 +540,14 @@ TEST_F(UniqueRefTest, HashIsDifferent_NullptrLeft) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
EXPECT_NE(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); EXPECT_NE(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, HashIsDifferent_NullptrRight) { TEST_F(UniqueRefTest, HashIsDifferent_NullptrRight) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_NE(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); EXPECT_NE(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, HashIsSame_BothNullptr) { TEST_F(UniqueRefTest, HashIsSame_BothNullptr) {
@ -555,7 +555,7 @@ TEST_F(UniqueRefTest, HashIsSame_BothNullptr) {
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_EQ(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); EXPECT_EQ(std::hash<unique_ref<int>>()(var1), std::hash<unique_ref<int>>()(var2)); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, OneIsLess) { TEST_F(UniqueRefTest, OneIsLess) {
@ -568,14 +568,14 @@ TEST_F(UniqueRefTest, NullptrIsLess1) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
EXPECT_TRUE(std::less<unique_ref<int>>()(var1, var2)); EXPECT_TRUE(std::less<unique_ref<int>>()(var1, var2)); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, NullptrIsLess2) { TEST_F(UniqueRefTest, NullptrIsLess2) {
unique_ref<int> var1 = make_unique_ref<int>(3); unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_FALSE(std::less<unique_ref<int>>()(var1, var2)); EXPECT_FALSE(std::less<unique_ref<int>>()(var1, var2)); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) { TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) {
@ -583,7 +583,7 @@ TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) {
unique_ref<int> var2 = make_unique_ref<int>(3); unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1)); makeInvalid(std::move(var1));
makeInvalid(std::move(var2)); makeInvalid(std::move(var2));
EXPECT_FALSE(std::less<unique_ref<int>>()(var1, var2)); EXPECT_FALSE(std::less<unique_ref<int>>()(var1, var2)); // NOLINT (intentional use-after-move)
} }
namespace { namespace {
@ -656,7 +656,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithDefaultDeleter_whenDestructCalled_thenCa
auto obj = make_unique_ref<DestructableMock>(&wasDestructed); auto obj = make_unique_ref<DestructableMock>(&wasDestructed);
destruct(std::move(obj)); destruct(std::move(obj));
EXPECT_TRUE(wasDestructed); EXPECT_TRUE(wasDestructed);
EXPECT_FALSE(obj.is_valid()); EXPECT_FALSE(obj.is_valid()); // NOLINT (intentional use-after-move)
} }
namespace { namespace {
@ -703,7 +703,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithCustomDefaultConstructibleDeleter_whenDe
auto obj = nullcheck(std::unique_ptr<bool, SetToTrueDeleter>(&wasDestructed)).value(); auto obj = nullcheck(std::unique_ptr<bool, SetToTrueDeleter>(&wasDestructed)).value();
destruct(std::move(obj)); destruct(std::move(obj));
EXPECT_TRUE(wasDestructed); EXPECT_TRUE(wasDestructed);
EXPECT_FALSE(obj.is_valid()); EXPECT_FALSE(obj.is_valid()); // NOLINT (intentional use-after-move)
} }
namespace { namespace {
@ -753,7 +753,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithCustomDeleterInstance_whenDestructCalled
auto obj = nullcheck(std::unique_ptr<int, SetToDeleter>(&value, SetToDeleter(4))).value(); auto obj = nullcheck(std::unique_ptr<int, SetToDeleter>(&value, SetToDeleter(4))).value();
destruct(std::move(obj)); destruct(std::move(obj));
EXPECT_EQ(4, value); EXPECT_EQ(4, value);
EXPECT_FALSE(obj.is_valid()); EXPECT_FALSE(obj.is_valid()); // NOLINT (intentional use-after-move)
} }
TEST_F(UniqueRefTest, givenUniquePtrWithCustomDeleterInstance_whenMovedToUniquePtr_thenHasSameDeleterInstance) { TEST_F(UniqueRefTest, givenUniquePtrWithCustomDeleterInstance_whenMovedToUniquePtr_thenHasSameDeleterInstance) {

View File

@ -31,13 +31,33 @@ function(target_activate_cpp14 TARGET)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE) endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE)
endfunction(target_activate_cpp14) endfunction(target_activate_cpp14)
# Find clang-tidy executable (for use in target_enable_style_warnings)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(WARNING "clang-tidy not found. Checks are disabled")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-system-headers=0")
endif()
################################################# #################################################
# Enable style compiler warnings # Enable style compiler warnings
# #
# Uses: target_enable_style_warnings(buildtarget) # Uses: target_enable_style_warnings(buildtarget)
################################################# #################################################
function(target_enable_style_warnings TARGET) function(target_enable_style_warnings TARGET)
# Enable compiler options
target_compile_options(${TARGET} PRIVATE -Wall -Wextra) target_compile_options(${TARGET} PRIVATE -Wall -Wextra)
# Enable clang-tidy
set_target_properties(
${TARGET} PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
endfunction(target_enable_style_warnings) endfunction(target_enable_style_warnings)
################################################## ##################################################

1
vendor/README vendored
View File

@ -2,4 +2,5 @@ This directory contains external projects, taken from the following locations:
scrypt: http://www.tarsnap.com/scrypt.html scrypt: http://www.tarsnap.com/scrypt.html
- changed: commented out compiler warnings about a workaround for a llvm bug - changed: commented out compiler warnings about a workaround for a llvm bug
googletest: https://github.com/google/googletest/tree/release-1.8.0 googletest: https://github.com/google/googletest/tree/release-1.8.0
- changed: added NOLINT comment as workaround for clang-tidy warning https://github.com/google/googletest/issues/853
spdlog: https://github.com/gabime/spdlog/tree/v0.14.0/include/spdlog spdlog: https://github.com/gabime/spdlog/tree/v0.14.0/include/spdlog

View File

@ -1269,7 +1269,7 @@ class MockSpec {
const char* file, int line, const char* obj, const char* call) { const char* file, int line, const char* obj, const char* call) {
const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
return function_mocker_->AddNewExpectation( return function_mocker_->AddNewExpectation( // NOLINT (workaround https://github.com/google/googletest/issues/853)
file, line, source_text, matchers_); file, line, source_text, matchers_);
} }