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)
# 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)

View File

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

View File

@ -40,10 +40,12 @@ optional_ownership_ptr<DataInnerNode> GetLowestInnerRightBorderNodeWithCondition
if (condition(*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) {
currentNode = cpputils::WithOwnership(std::move(*lastChild));
if (lastChild == none) {
// lastChild is a leaf
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;

View File

@ -33,7 +33,7 @@ optional<unique_ref<DataTreeRef>> ParallelAccessDataTreeStore::load(const blocks
unique_ref<DataTreeRef> 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<DataTreeRef> tree) {

View File

@ -57,7 +57,7 @@ unique_ref<Block> 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> block) {

View File

@ -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();

View File

@ -72,7 +72,7 @@ unique_ref<DirBlobRef> CryDir::LoadBlob() const {
unique_ref<vector<fspp::Dir::Entry>> 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);
}

View File

@ -45,7 +45,7 @@ unique_ref<fspp::OpenFile> 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());
}

View File

@ -155,7 +155,7 @@ const CryDevice *CryNode::device() const {
unique_ref<FsBlobRef> 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 {

View File

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

View File

@ -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();
}

View File

@ -18,7 +18,7 @@ namespace cryfs {
namespace parallelaccessfsblobstore {
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);
if (fileBlob != nullptr) {
return unique_ref<FsBlobRef>(make_unique_ref<FileBlobRef>(fileBlob));

View File

@ -49,22 +49,22 @@ public:
void EXPECT_LEFT_IS(const Expected &expected, either<Left, Right> &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<Left, Right> &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<class Left, class Right, class Expected>
void EXPECT_RIGHT_IS(const Expected &expected, either<Left, Right> &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<Left, Right> &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<string, int> val = string("mystring1");
val.left_opt().get() = "mystring2";
val.left_opt().value() = "mystring2";
EXPECT_LEFT_IS("mystring2", val);
}
TEST_F(EitherTest, ModifyRightOpt) {
either<int, string> val = string("mystring1");
val.right_opt().get() = "mystring2";
val.right_opt().value() = "mystring2";
EXPECT_RIGHT_IS("mystring2", val);
}

View File

@ -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) {

View File

@ -190,21 +190,21 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveAssigning_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
unique_ref<SomeClass> obj2 = make_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_whenMoveAssigningToBaseClass_thenPointsToSameObject) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
unique_ref<SomeBaseClass> base = make_unique_ref<SomeBaseClass>(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<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
unique_ref<SomeBaseClass> obj2 = make_unique_ref<SomeBaseClass>(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<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::unique_ptr<SomeClass> obj2 = std::make_unique<SomeClass>();
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<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
std::unique_ptr<SomeBaseClass> obj2 = std::make_unique<SomeBaseClass>(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<SomeClass> obj1 = make_unique_ref<SomeClass>();
std::shared_ptr<SomeClass> obj2 = std::make_shared<SomeClass>();
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<SomeChildClass> obj1 = make_unique_ref<SomeChildClass>(3);
std::shared_ptr<SomeBaseClass> obj2 = std::make_shared<SomeBaseClass>(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<SomeClass> obj1 = make_unique_ref<SomeClass>();
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) {
@ -287,7 +287,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClass_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
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) {
@ -300,7 +300,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToUniquePtr_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
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) {
@ -312,7 +312,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_th
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassUniquePtr_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
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) {
@ -325,7 +325,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenPointsT
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToSharedPtr_thenOldInstanceInvalid) {
unique_ref<SomeClass> obj1 = make_unique_ref<SomeClass>();
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) {
@ -337,7 +337,7 @@ TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_th
TEST_F(UniqueRefTest, givenUniqueRef_whenMoveConstructingToBaseClassSharedPtr_thenOldInstanceInvalid) {
unique_ref<SomeChildClass> child = make_unique_ref<SomeChildClass>(3);
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) {
@ -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<int> var2 = make_unique_ref<int>(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<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(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<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(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<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3);
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) {
unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3);
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) {
@ -555,7 +555,7 @@ TEST_F(UniqueRefTest, HashIsSame_BothNullptr) {
unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1));
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) {
@ -568,14 +568,14 @@ TEST_F(UniqueRefTest, NullptrIsLess1) {
unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3);
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) {
unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3);
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) {
@ -583,7 +583,7 @@ TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) {
unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var1));
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 {
@ -656,7 +656,7 @@ TEST_F(UniqueRefTest, givenUniqueRefWithDefaultDeleter_whenDestructCalled_thenCa
auto obj = make_unique_ref<DestructableMock>(&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<bool, SetToTrueDeleter>(&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<int, SetToDeleter>(&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) {

View File

@ -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)
##################################################

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
- 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

View File

@ -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_);
}