Use =delete to disable special member functions

This has the benefits of:
- Easier to understand compiler error messages
- Moves some errors from link-time to compile-time
- NonCopyable classes can still specify default move constructors
This commit is contained in:
sfc-gh-tclinkenbeard 2020-08-18 11:02:57 -07:00
parent dee8df9b48
commit 7b210aee24
5 changed files with 13 additions and 15 deletions

View File

@ -345,7 +345,7 @@ public:
std::vector<std::unique_ptr<SpecialKeyRangeReadImpl>> specialKeySpaceModules; std::vector<std::unique_ptr<SpecialKeyRangeReadImpl>> specialKeySpaceModules;
std::unique_ptr<SpecialKeySpace> specialKeySpace; std::unique_ptr<SpecialKeySpace> specialKeySpace;
void registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, SpecialKeySpace::IMPLTYPE type, void registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, SpecialKeySpace::IMPLTYPE type,
std::unique_ptr<SpecialKeyRangeReadImpl> impl); std::unique_ptr<SpecialKeyRangeReadImpl> &&impl);
static bool debugUseTags; static bool debugUseTags;
static const std::vector<std::string> debugTransactionTagChoices; static const std::vector<std::string> debugTransactionTagChoices;

View File

@ -697,7 +697,7 @@ Future<HealthMetrics> DatabaseContext::getHealthMetrics(bool detailed = false) {
} }
void DatabaseContext::registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, SpecialKeySpace::IMPLTYPE type, void DatabaseContext::registerSpecialKeySpaceModule(SpecialKeySpace::MODULE module, SpecialKeySpace::IMPLTYPE type,
std::unique_ptr<SpecialKeyRangeReadImpl> impl) { std::unique_ptr<SpecialKeyRangeReadImpl> &&impl) {
specialKeySpace->registerKeyRange(module, type, impl->getKeyRange(), impl.get()); specialKeySpace->registerKeyRange(module, type, impl->getKeyRange(), impl.get());
specialKeySpaceModules.push_back(std::move(impl)); specialKeySpaceModules.push_back(std::move(impl));
} }

View File

@ -85,11 +85,12 @@ struct TrackIt {
class NonCopyable class NonCopyable
{ {
protected: protected:
NonCopyable () {} NonCopyable()=default;
~NonCopyable () {} /// Protected non-virtual destructor ~NonCopyable()=default; /// Protected non-virtual destructor
private: NonCopyable(NonCopyable&&)=default;
NonCopyable (const NonCopyable &); NonCopyable &operator=(NonCopyable&&)=default;
NonCopyable & operator = (const NonCopyable &); NonCopyable(const NonCopyable&)=delete;
NonCopyable &operator=(const NonCopyable &)=delete;
}; };
// An Arena is a custom allocator that consists of a set of ArenaBlocks. Allocation is performed by bumping a pointer // An Arena is a custom allocator that consists of a set of ArenaBlocks. Allocation is performed by bumping a pointer
@ -174,9 +175,7 @@ struct ArenaBlock : NonCopyable, ThreadSafeReferenceCounted<ArenaBlock>
static ArenaBlock* create(int dataSize, Reference<ArenaBlock>& next); static ArenaBlock* create(int dataSize, Reference<ArenaBlock>& next);
void destroy(); void destroy();
void destroyLeaf(); void destroyLeaf();
static void* operator new(size_t s)=delete;
private:
static void* operator new(size_t s); // not implemented
}; };
inline void* operator new ( size_t size, Arena& p ) { inline void* operator new ( size_t size, Arena& p ) {

View File

@ -118,6 +118,7 @@ public:
static volatile int32_t pageCount; static volatile int32_t pageCount;
#endif #endif
FastAllocator()=delete;
private: private:
#ifdef VALGRIND #ifdef VALGRIND
static unsigned long vLock; static unsigned long vLock;
@ -147,7 +148,6 @@ private:
} }
static void* freelist; static void* freelist;
FastAllocator(); // not implemented
static void initThread(); static void initThread();
static void getMagazine(); static void getMagazine();
static void releaseMagazine(void*); static void releaseMagazine(void*);

View File

@ -71,11 +71,10 @@ class ThreadPool : public IThreadPool, public ReferenceCounted<ThreadPool> {
PThreadAction action; PThreadAction action;
ActionWrapper(PThreadAction action) : action(action) {} ActionWrapper(PThreadAction action) : action(action) {}
// HACK: Boost won't use move constructors, so we just assume the last copy made is the one that will be called or cancelled // HACK: Boost won't use move constructors, so we just assume the last copy made is the one that will be called or cancelled
ActionWrapper(ActionWrapper const& r) : action(r.action) { const_cast<ActionWrapper&>(r).action=NULL; } ActionWrapper(ActionWrapper const& r) : action(r.action) { const_cast<ActionWrapper&>(r).action=nullptr; }
void operator()() { Thread::dispatch(action); action = NULL; } void operator()() { Thread::dispatch(action); action = nullptr; }
~ActionWrapper() { if (action) { action->cancel(); } } ~ActionWrapper() { if (action) { action->cancel(); } }
private: ActionWrapper &operator=(ActionWrapper const&)=delete;
ActionWrapper &operator=(ActionWrapper const&);
}; };
public: public:
ThreadPool(int stackSize) : dontstop(ios), mode(Run), stackSize(stackSize) {} ThreadPool(int stackSize) : dontstop(ios), mode(Run), stackSize(stackSize) {}