diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..1c3c1c66 --- /dev/null +++ b/.clang-tidy @@ -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' +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index 04ac2aa8..26080cf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ 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) include(utils.cmake) diff --git a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp index f06d1b3c..7b35e428 100644 --- a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp +++ b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp @@ -28,7 +28,7 @@ BlobOnBlocks::BlobOnBlocks(unique_ref datatree) } BlobOnBlocks::~BlobOnBlocks() { -} +} // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 ) uint64_t BlobOnBlocks::size() const { if (_sizeCache == boost::none) { diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp index 687d1c64..138ceda3 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp @@ -40,10 +40,12 @@ optional_ownership_ptr GetLowestInnerRightBorderNodeWithCondition if (condition(*currentNode)) { result = std::move(currentNode); } - ASSERT(lastChild != none || static_cast(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) { - currentNode = cpputils::WithOwnership(std::move(*lastChild)); + if (lastChild == none) { + // lastChild is a leaf + ASSERT(static_cast(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; diff --git a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp index ef65c7cc..69f9a606 100644 --- a/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp +++ b/src/blobstore/implementations/onblocks/parallelaccessdatatreestore/ParallelAccessDataTreeStore.cpp @@ -33,7 +33,7 @@ optional> ParallelAccessDataTreeStore::load(const blocks unique_ref ParallelAccessDataTreeStore::createNewTree() { auto dataTree = _dataTreeStore->createNewTree(); 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 tree) { diff --git a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp index 1005cf57..effa6e23 100644 --- a/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp +++ b/src/blockstore/implementations/parallelaccess/ParallelAccessBlockStore.cpp @@ -57,7 +57,7 @@ unique_ref ParallelAccessBlockStore::overwrite(const BlockId &blockId, Da auto onAdd = [this, blockId, &data] { 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) { diff --git a/src/cryfs/filesystem/CryDevice.cpp b/src/cryfs/filesystem/CryDevice.cpp index 5b32dc85..3eee24a0 100644 --- a/src/cryfs/filesystem/CryDevice.cpp +++ b/src/cryfs/filesystem/CryDevice.cpp @@ -289,7 +289,7 @@ void CryDevice::RemoveBlob(const blockstore::BlockId &blockId) { BlockId CryDevice::GetOrCreateRootBlobId(CryConfigFile *configFile) { 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(); configFile->config()->SetRootBlob(new_blockId.ToString()); configFile->save(); diff --git a/src/cryfs/filesystem/CryDir.cpp b/src/cryfs/filesystem/CryDir.cpp index e5151281..3d2e116e 100644 --- a/src/cryfs/filesystem/CryDir.cpp +++ b/src/cryfs/filesystem/CryDir.cpp @@ -72,7 +72,7 @@ unique_ref CryDir::LoadBlob() const { unique_ref> CryDir::children() { 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) parent()->updateAccessTimestampForChild(blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME); } diff --git a/src/cryfs/filesystem/CryFile.cpp b/src/cryfs/filesystem/CryFile.cpp index c7422072..6aa2cadf 100644 --- a/src/cryfs/filesystem/CryFile.cpp +++ b/src/cryfs/filesystem/CryFile.cpp @@ -45,7 +45,7 @@ unique_ref CryFile::open(int flags) { void CryFile::truncate(off_t size) { device()->callFsActionCallbacks(); - auto blob = LoadBlob(); + auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 ) blob->resize(size); parent()->updateModificationTimestampForChild(blockId()); } diff --git a/src/cryfs/filesystem/CryNode.cpp b/src/cryfs/filesystem/CryNode.cpp index df17e7ab..c632d9ff 100644 --- a/src/cryfs/filesystem/CryNode.cpp +++ b/src/cryfs/filesystem/CryNode.cpp @@ -155,7 +155,7 @@ const CryDevice *CryNode::device() const { unique_ref CryNode::LoadBlob() const { auto blob = _device->LoadBlob(_blockId); 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 { diff --git a/src/cryfs/filesystem/CryOpenFile.cpp b/src/cryfs/filesystem/CryOpenFile.cpp index b0b68f06..7d8eb1a7 100644 --- a/src/cryfs/filesystem/CryOpenFile.cpp +++ b/src/cryfs/filesystem/CryOpenFile.cpp @@ -25,7 +25,7 @@ CryOpenFile::CryOpenFile(const CryDevice *device, shared_ptr parent, CryOpenFile::~CryOpenFile() { //TODO -} +} // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 ) void CryOpenFile::flush() { _device->callFsActionCallbacks(); diff --git a/src/cryfs/filesystem/CrySymlink.cpp b/src/cryfs/filesystem/CrySymlink.cpp index 7677a4e8..bbf4a7f7 100644 --- a/src/cryfs/filesystem/CrySymlink.cpp +++ b/src/cryfs/filesystem/CrySymlink.cpp @@ -48,7 +48,7 @@ fspp::Dir::EntryType CrySymlink::getType() const { bf::path CrySymlink::target() { device()->callFsActionCallbacks(); 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(); } diff --git a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp index 02089ef7..09c2ac83 100644 --- a/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp +++ b/src/cryfs/filesystem/parallelaccessfsblobstore/ParallelAccessFsBlobStore.cpp @@ -18,7 +18,7 @@ namespace cryfs { namespace parallelaccessfsblobstore { optional> 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(blob); if (fileBlob != nullptr) { return unique_ref(make_unique_ref(fileBlob)); diff --git a/src/parallelaccessstore/ParallelAccessStore.h b/src/parallelaccessstore/ParallelAccessStore.h index 2c811549..84812f9d 100644 --- a/src/parallelaccessstore/ParallelAccessStore.h +++ b/src/parallelaccessstore/ParallelAccessStore.h @@ -210,7 +210,7 @@ void ParallelAccessStore::remove(const Key &key, cpp template std::future> ParallelAccessStore::_resourceToRemoveFuture(const Key &key) { std::lock_guard 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>()); ASSERT(true == insertResult.second, "Inserting failed"); return insertResult.first->second.get_future(); }; diff --git a/test/cpp-utils/EitherTest.cpp b/test/cpp-utils/EitherTest.cpp index e5555318..656b6610 100644 --- a/test/cpp-utils/EitherTest.cpp +++ b/test/cpp-utils/EitherTest.cpp @@ -49,22 +49,22 @@ public: void EXPECT_LEFT_IS(const Expected &expected, either &value) { EXPECT_IS_LEFT(value); 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()); const either &const_value = value; 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()); } template void EXPECT_RIGHT_IS(const Expected &expected, either &value) { EXPECT_IS_RIGHT(value); 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()); const either &const_value = value; 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()); } }; @@ -244,13 +244,13 @@ TEST_F(EitherTest, ModifyRight) { TEST_F(EitherTest, ModifyLeftOpt) { either val = string("mystring1"); - val.left_opt().get() = "mystring2"; + val.left_opt().value() = "mystring2"; EXPECT_LEFT_IS("mystring2", val); } TEST_F(EitherTest, ModifyRightOpt) { either val = string("mystring1"); - val.right_opt().get() = "mystring2"; + val.right_opt().value() = "mystring2"; EXPECT_RIGHT_IS("mystring2", val); } diff --git a/test/cpp-utils/data/DataTest.cpp b/test/cpp-utils/data/DataTest.cpp index 937bbe04..7c0e7141 100644 --- a/test/cpp-utils/data/DataTest.cpp +++ b/test/cpp-utils/data/DataTest.cpp @@ -141,8 +141,8 @@ TEST_F(DataTest, MoveConstructor) { Data original = DataFixture::generate(1024); Data copy(std::move(original)); EXPECT_EQ(DataFixture::generate(1024), copy); - EXPECT_EQ(nullptr, original.data()); - EXPECT_EQ(0u, original.size()); + EXPECT_EQ(nullptr, original.data()); // NOLINT (intentional use-after-move) + EXPECT_EQ(0u, original.size()); // NOLINT (intentional use-after-move) } TEST_F(DataTest, MoveAssignment) { @@ -150,8 +150,8 @@ TEST_F(DataTest, MoveAssignment) { Data copy(0); copy = std::move(original); EXPECT_EQ(DataFixture::generate(1024), copy); - EXPECT_EQ(nullptr, original.data()); - EXPECT_EQ(0u, original.size()); + EXPECT_EQ(nullptr, original.data()); // NOLINT (intentional use-after-move) + EXPECT_EQ(0u, original.size()); // NOLINT (intentional use-after-move) } TEST_F(DataTest, Equality) { diff --git a/test/cpp-utils/pointer/unique_ref_test.cpp b/test/cpp-utils/pointer/unique_ref_test.cpp index 100b231a..955212b5 100644 --- a/test/cpp-utils/pointer/unique_ref_test.cpp +++ b/test/cpp-utils/pointer/unique_ref_test.cpp @@ -190,21 +190,21 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigning_thenOldInstanceInvalid) { unique_ref obj1 = make_unique_ref(); unique_ref obj2 = make_unique_ref(); 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) { unique_ref child = make_unique_ref(3); unique_ref base = make_unique_ref(10); 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) { unique_ref obj1 = make_unique_ref(3); unique_ref obj2 = make_unique_ref(10); 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) { @@ -219,7 +219,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToUniquePtr_thenOldInstanc unique_ref obj1 = make_unique_ref(); std::unique_ptr obj2 = std::make_unique(); 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) { @@ -233,7 +233,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassUniquePtr_thenO unique_ref obj1 = make_unique_ref(3); std::unique_ptr obj2 = std::make_unique(10); 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) { @@ -248,7 +248,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToSharedPtr_thenOldInstanc unique_ref obj1 = make_unique_ref(); std::shared_ptr obj2 = std::make_shared(); 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) { @@ -262,7 +262,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigningToBaseClassSharedPtr_thenO unique_ref obj1 = make_unique_ref(3); std::shared_ptr obj2 = std::make_shared(10); 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) { @@ -275,7 +275,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenPointsToSameObject TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructing_thenOldInstanceInvalid) { unique_ref obj1 = make_unique_ref(); unique_ref 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) { @@ -287,7 +287,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenPointsT TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenOldInstanceInvalid) { unique_ref child = make_unique_ref(3); unique_ref 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) { @@ -300,7 +300,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenPointsT TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenOldInstanceInvalid) { unique_ref obj1 = make_unique_ref(); std::unique_ptr 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) { @@ -312,7 +312,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_th TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenOldInstanceInvalid) { unique_ref child = make_unique_ref(3); std::unique_ptr 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) { @@ -325,7 +325,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenPointsT TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenOldInstanceInvalid) { unique_ref obj1 = make_unique_ref(); std::shared_ptr 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) { @@ -337,7 +337,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_th TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenOldInstanceInvalid) { unique_ref child = make_unique_ref(3); std::shared_ptr base = std::move(child); - EXPECT_FALSE(child.is_valid()); + EXPECT_FALSE(child.is_valid()); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, Swap) { @@ -388,7 +388,7 @@ TEST_F(UniqueRefTest, SwapFromRValue) { SomeClass *obj1ptr = obj1.get(); SomeClass *obj2ptr = obj2.get(); 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()); } @@ -399,7 +399,7 @@ TEST_F(UniqueRefTest, SwapWithRValue) { SomeClass *obj2ptr = obj2.get(); std::swap(obj1, std::move(obj2)); 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) { @@ -503,8 +503,8 @@ TEST_F(UniqueRefTest, Equality_Nullptr) { unique_ref var2 = make_unique_ref(4); makeInvalid(std::move(var1)); makeInvalid(std::move(var2)); - EXPECT_TRUE(var1 == var2); - EXPECT_FALSE(var1 != var2); + EXPECT_TRUE(var1 == var2); // NOLINT (intentional use-after-move) + EXPECT_FALSE(var1 != var2); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, Nonequality) { @@ -518,16 +518,16 @@ TEST_F(UniqueRefTest, Nonequality_NullptrLeft) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var1)); - EXPECT_TRUE(var1 != var2); - EXPECT_FALSE(var1 == var2); + EXPECT_TRUE(var1 != var2); // NOLINT (intentional use-after-move) + EXPECT_FALSE(var1 == var2); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, Nonequality_NullptrRight) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var2)); - EXPECT_TRUE(var1 != var2); - EXPECT_FALSE(var1 == var2); + EXPECT_TRUE(var1 != var2); // NOLINT (intentional use-after-move) + EXPECT_FALSE(var1 == var2); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, HashIsDifferent) { @@ -540,14 +540,14 @@ TEST_F(UniqueRefTest, HashIsDifferent_NullptrLeft) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var1)); - EXPECT_NE(std::hash>()(var1), std::hash>()(var2)); + EXPECT_NE(std::hash>()(var1), std::hash>()(var2)); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, HashIsDifferent_NullptrRight) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var2)); - EXPECT_NE(std::hash>()(var1), std::hash>()(var2)); + EXPECT_NE(std::hash>()(var1), std::hash>()(var2)); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, HashIsSame_BothNullptr) { @@ -555,7 +555,7 @@ TEST_F(UniqueRefTest, HashIsSame_BothNullptr) { unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var1)); makeInvalid(std::move(var2)); - EXPECT_EQ(std::hash>()(var1), std::hash>()(var2)); + EXPECT_EQ(std::hash>()(var1), std::hash>()(var2)); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, OneIsLess) { @@ -568,14 +568,14 @@ TEST_F(UniqueRefTest, NullptrIsLess1) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var1)); - EXPECT_TRUE(std::less>()(var1, var2)); + EXPECT_TRUE(std::less>()(var1, var2)); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, NullptrIsLess2) { unique_ref var1 = make_unique_ref(3); unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var2)); - EXPECT_FALSE(std::less>()(var1, var2)); + EXPECT_FALSE(std::less>()(var1, var2)); // NOLINT (intentional use-after-move) } TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) { @@ -583,7 +583,7 @@ TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) { unique_ref var2 = make_unique_ref(3); makeInvalid(std::move(var1)); makeInvalid(std::move(var2)); - EXPECT_FALSE(std::less>()(var1, var2)); + EXPECT_FALSE(std::less>()(var1, var2)); // NOLINT (intentional use-after-move) } namespace { @@ -656,7 +656,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithDefaultDeleter_whenDestructCalled_thenCa auto obj = make_unique_ref(&wasDestructed); destruct(std::move(obj)); EXPECT_TRUE(wasDestructed); - EXPECT_FALSE(obj.is_valid()); + EXPECT_FALSE(obj.is_valid()); // NOLINT (intentional use-after-move) } namespace { @@ -703,7 +703,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithCustomDefaultConstructibleDeleter_whenDe auto obj = nullcheck(std::unique_ptr(&wasDestructed)).value(); destruct(std::move(obj)); EXPECT_TRUE(wasDestructed); - EXPECT_FALSE(obj.is_valid()); + EXPECT_FALSE(obj.is_valid()); // NOLINT (intentional use-after-move) } namespace { @@ -753,7 +753,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithCustomDeleterInstance_whenDestructCalled auto obj = nullcheck(std::unique_ptr(&value, SetToDeleter(4))).value(); destruct(std::move(obj)); 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) { diff --git a/utils.cmake b/utils.cmake index c4ff9653..d359c943 100644 --- a/utils.cmake +++ b/utils.cmake @@ -31,13 +31,33 @@ function(target_activate_cpp14 TARGET) endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE) 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 # # Uses: target_enable_style_warnings(buildtarget) ################################################# function(target_enable_style_warnings TARGET) + # Enable compiler options 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) ################################################## diff --git a/vendor/README b/vendor/README index 0d007909..6473a604 100644 --- a/vendor/README +++ b/vendor/README @@ -2,4 +2,5 @@ This directory contains external projects, taken from the following locations: scrypt: http://www.tarsnap.com/scrypt.html - changed: commented out compiler warnings about a workaround for a llvm bug 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 diff --git a/vendor/googletest/gtest-1.8.0/googlemock/include/gmock/gmock-spec-builders.h b/vendor/googletest/gtest-1.8.0/googlemock/include/gmock/gmock-spec-builders.h index fed7de66..60ed1a7c 100644 --- a/vendor/googletest/gtest-1.8.0/googlemock/include/gmock/gmock-spec-builders.h +++ b/vendor/googletest/gtest-1.8.0/googlemock/include/gmock/gmock-spec-builders.h @@ -1269,7 +1269,7 @@ class MockSpec { const char* file, int line, const char* obj, const char* call) { const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); 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_); }