Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggressively implement rule of 5 #1621

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Checks: '
-clang-diagnostic-range-loop-analysis,
-clang-analyzer-core.StackAddressEscape,

cppcoreguidelines-special-member-functions,

misc-*,
-misc-macro-parentheses,
-misc-non-private-member-variables-in-classes,
Expand Down
6 changes: 6 additions & 0 deletions hilti/runtime/include/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ inline std::ostream& operator<<(std::ostream& stream, const Exception& e) { retu
name(std::string_view desc) : base(Internal(), #name, desc) {} \
name(std::string_view desc, std::string_view location) : base(Internal(), #name, desc, location) {} \
virtual ~name(); /* required to create vtable, see hilti::rt::Exception */ \
\
name(const name&) = default; \
name(name&&) = default; \
name& operator=(const name&) = default; \
name& operator=(name&&) = default; \
\
protected: \
using base::base; \
}; // namespace hilti::rt
Expand Down
17 changes: 15 additions & 2 deletions hilti/runtime/include/fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct FiberContext {
FiberContext();
~FiberContext();

FiberContext(const FiberContext&) = delete;
FiberContext(FiberContext&&) = default;

FiberContext& operator=(const FiberContext&) = delete;
FiberContext& operator=(FiberContext&&) = default;

/** (Pseudo-)fiber representing the main function. */
std::unique_ptr<detail::Fiber> main;

Expand Down Expand Up @@ -75,6 +81,11 @@ struct StackBuffer {
*/
StackBuffer(const ::Fiber* fiber) : _fiber(fiber) {}

StackBuffer(const StackBuffer&) = delete;
StackBuffer(StackBuffer&&) = default;
StackBuffer& operator=(const StackBuffer&) = delete;
StackBuffer& operator=(StackBuffer&&) = default;

/** Destructor. */
~StackBuffer();

Expand Down Expand Up @@ -134,12 +145,14 @@ class Callback {
return hilti::rt::any_cast<F>(f)(h);
}) {}

Callback(const Callback&) = default;
Callback(const Callback&) = delete;
Callback(Callback&&) = default;

Callback& operator=(const Callback&) = default;
Callback& operator=(const Callback&) = delete;
Callback& operator=(Callback&&) = default;

~Callback() = default;

hilti::rt::any operator()(resumable::Handle* h) const { return _invoke(_f, h); }

private:
Expand Down
3 changes: 3 additions & 0 deletions hilti/runtime/include/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Range {

Range(const Range&) = delete;
Range(Range&&) = delete;

~Range() = default;

Range& operator=(const Range&) = delete;
Range& operator=(Range&&) = delete;

Expand Down
15 changes: 15 additions & 0 deletions hilti/runtime/include/test/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class TemporaryFile {
hilti::rt::filesystem::remove_all(_path, ec); // Swallow any error from removal.
}

TemporaryFile(const TemporaryFile&) = delete;
TemporaryFile(TemporaryFile&&) = default;
TemporaryFile& operator=(const TemporaryFile&) = delete;
TemporaryFile& operator=(TemporaryFile&&) = default;

private:
hilti::rt::filesystem::path _path;
};
Expand All @@ -65,6 +70,11 @@ class CaptureIO {
CaptureIO(std::ostream& stream) : _old(stream.rdbuf(_buffer.rdbuf())), _stream(&stream) {}
~CaptureIO() { _stream->rdbuf(_old); }

CaptureIO(const CaptureIO&) = delete;
CaptureIO(CaptureIO&&) = default;
CaptureIO& operator=(const CaptureIO&) = delete;
CaptureIO& operator=(CaptureIO&&) = default;

auto str() const { return _buffer.str(); }

private:
Expand All @@ -83,6 +93,11 @@ class TestContext {

~TestContext() { context::detail::current() = _prev; }

TestContext(const TestContext&) = delete;
TestContext(TestContext&&) = default;
TestContext& operator=(const TestContext&) = delete;
TestContext& operator=(TestContext&&) = default;

private:
Context* _prev = nullptr;
};
Expand Down
2 changes: 2 additions & 0 deletions hilti/runtime/include/types/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class Bytes : protected std::string {
Bytes(const Bytes& xs) : Base(xs) {}
Bytes(Bytes&& xs) noexcept : Base(std::move(xs)) {}

~Bytes() = default;

/** Replaces the contents of this `Bytes` with another `Bytes`.
*
* This function invalidates all iterators.
Expand Down
2 changes: 2 additions & 0 deletions hilti/runtime/include/types/reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ class StrongReference : public std::shared_ptr<T> {
/** Move constructor. */
StrongReference(StrongReference&& other) noexcept : Base(std::move(other)) {}

~StrongReference() = default;

/**
* Returns true if the reference does not refer any value.
*/
Expand Down
7 changes: 6 additions & 1 deletion hilti/runtime/include/types/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class Chain : public intrusive_ptr::ManagedObject {
using UnsafeConstIterator = stream::detail::UnsafeConstIterator;
using Size = stream::Size;

Chain() {}
Chain() = default;
~Chain() = default;

/** Moves a chunk and all its successors into a new chain. */
Chain(std::unique_ptr<Chunk> head) : _head(std::move(head)), _tail(_head->last()) { _head->setChain(this); }
Expand Down Expand Up @@ -365,6 +366,8 @@ class SafeConstIterator {
/** Constructor. */
SafeConstIterator() = default;

~SafeConstIterator() = default;

SafeConstIterator(const SafeConstIterator&) = default;
SafeConstIterator(SafeConstIterator&&) = default;

Expand Down Expand Up @@ -1017,6 +1020,8 @@ class View final {
/** Constructor. */
View() = default;

~View() = default;

View(const View&) = default;
View(View&&) = default;

Expand Down
5 changes: 5 additions & 0 deletions hilti/runtime/src/tests/exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class TestLocation {
debug::setLocation(nullptr);
}

TestLocation(const TestLocation&) = delete;
TestLocation(TestLocation&&) = delete;
TestLocation& operator=(const TestLocation&) = delete;
TestLocation& operator=(TestLocation&&) = delete;

private:
std::string _location;
Context* _prev = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions hilti/runtime/src/tests/hilti.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class TestCout {

~TestCout() { configuration::detail::__configuration = std::move(_prev); }

TestCout(const TestCout&) = delete;
TestCout(TestCout&&) = delete;
TestCout& operator=(const TestCout&) = delete;
TestCout& operator=(TestCout&&) = delete;

auto str() const { return _cout.str(); }

private:
Expand Down
10 changes: 10 additions & 0 deletions hilti/runtime/src/tests/intrusive-ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Managed : public intrusive_ptr::ManagedObject {
Managed() { ++instances; }
~Managed() { --instances; }
static inline int instances = 0;

Managed(const Managed&) = delete;
Managed(Managed&&) = default;
Managed& operator=(const Managed&) = delete;
Managed& operator=(Managed&&) = default;
};

using ManagedPtr = IntrusivePtr<Managed>;
Expand All @@ -50,6 +55,11 @@ struct TestObject : intrusive_ptr::ManagedObject {
TestObject() { ++instances; }
TestObject(int _i) : i(_i) { ++instances; }

TestObject(const TestObject&) = delete;
TestObject(TestObject&&) = default;
TestObject& operator=(const TestObject&) = delete;
TestObject& operator=(TestObject&&) = default;

~TestObject() { --instances; }

int i = 0;
Expand Down
5 changes: 5 additions & 0 deletions hilti/runtime/src/tests/library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class Env {
}
}

Env(const Env&) = delete;
Env(Env&&) = default;
Env& operator=(const Env&) = delete;
Env& operator=(Env&&) = default;

private:
std::pair<std::string, std::optional<std::string>> _prev;
};
Expand Down
5 changes: 5 additions & 0 deletions hilti/runtime/src/tests/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TestLogger {
std::swap(_prev, detail::globalState()->debug_logger);
}

TestLogger(const TestLogger&) = delete;
TestLogger(TestLogger&&) = default;
TestLogger& operator=(const TestLogger&) = delete;
TestLogger& operator=(TestLogger&&) = default;

~TestLogger() { detail::globalState()->debug_logger = std::move(_prev); }

auto lines() const { return _file.lines(); }
Expand Down
5 changes: 5 additions & 0 deletions hilti/runtime/src/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

struct RuntimeWrapper {
~RuntimeWrapper() { hilti::rt::done(); }
RuntimeWrapper() = default;
RuntimeWrapper(const RuntimeWrapper&) = delete;
RuntimeWrapper(RuntimeWrapper&&) = default;
RuntimeWrapper& operator=(const RuntimeWrapper&) = delete;
RuntimeWrapper& operator=(RuntimeWrapper&&) = default;
};

int main(int argc, char** argv) {
Expand Down
4 changes: 4 additions & 0 deletions hilti/runtime/src/tests/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ TEST_CASE("createTemporaryFile") {

struct Cleanup {
Cleanup(hilti::rt::filesystem::path& tmp) : _tmp(tmp) {}
Cleanup(const Cleanup&) = delete;
Cleanup(Cleanup&&) = default;
Cleanup& operator=(const Cleanup&) = delete;
Cleanup& operator=(Cleanup&&) = delete;
~Cleanup() {
std::error_code ec;
if ( hilti::rt::filesystem::exists(_tmp, ec) )
Expand Down
4 changes: 4 additions & 0 deletions hilti/runtime/src/types/regexp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class regexp::MatchState::Pimpl {
Pimpl(const Pimpl& other) : _acc(other._acc), _first(other._first), _re(other._re) {
jrx_match_state_copy(&other._ms, &_ms);
}

Pimpl(Pimpl&&) = default;
Pimpl& operator=(const Pimpl&) = default;
Pimpl& operator=(Pimpl&&) = default;
};

regexp::MatchState::MatchState(const RegExp& re) {
Expand Down
2 changes: 2 additions & 0 deletions hilti/toolchain/include/ast/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ struct Operand {
Operand(Operand&&) = default;
Operand(const Operand&) = default;

~Operand() = default;

Operand& operator=(Operand&&) = default;
Operand& operator=(const Operand&) = default;

Expand Down
5 changes: 5 additions & 0 deletions hilti/toolchain/include/base/visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ class Visitor {
Visitor() = default;
virtual ~Visitor() = default;

Visitor(const Visitor&) = default;
Visitor(Visitor&&) noexcept = default;
Visitor& operator=(const Visitor&) = default;
Visitor& operator=(Visitor&&) noexcept = default;

virtual void preDispatch(const Erased& /* n */, int /* level */){};

/** Execute matching dispatch methods for a single node. */
Expand Down
5 changes: 5 additions & 0 deletions hilti/toolchain/include/compiler/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class Context {
/** Destructor. */
~Context();

Context(const Context&) = default;
Context(Context&&) = default;
Context& operator=(const Context&) = default;
Context& operator=(Context&&) = default;

/** Returns the context's compiler options. */
const Options& options() const { return _options; }

Expand Down
2 changes: 2 additions & 0 deletions hilti/toolchain/include/compiler/detail/cxx/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct Local {
Local(const Local&) = default;
Local& operator=(Local&&) = default;
Local& operator=(const Local&) = default;
~Local() = default;

Local(cxx::ID _id = {}, cxx::Type _type = {}, std::vector<cxx::Expression> _args = {},
std::optional<cxx::Expression> _init = {}, Linkage _linkage = {})
: id(std::move(_id)),
Expand Down
6 changes: 5 additions & 1 deletion hilti/toolchain/include/compiler/optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace hilti {
struct Optimizer {
public:
Optimizer(const std::vector<std::shared_ptr<Unit>>& units) : _units(units) {}
~Optimizer() {}
Optimizer(const Optimizer&) = default;
Optimizer(Optimizer&&) = default;
Optimizer& operator=(const Optimizer&) = delete;
Optimizer& operator=(Optimizer&&) = delete;
~Optimizer() = default;

void run();

Expand Down
7 changes: 7 additions & 0 deletions hilti/toolchain/include/compiler/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ using MetaData = detail::cxx::linker::MetaData;
*/
class Unit {
public:
Unit() = default;
Unit(const Unit&) = default;
Unit(Unit&&) = default;

Unit& operator=(const Unit&) = default;
Unit& operator=(Unit&&) = default;

/** Destructor. */
~Unit();

Expand Down
5 changes: 5 additions & 0 deletions hilti/toolchain/src/compiler/codegen/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ struct GlobalsVisitor : hilti::visitor::PreOrder<void, GlobalsVisitor> {
GlobalsVisitor(const GlobalsVisitor&) = delete;
GlobalsVisitor(GlobalsVisitor&&) noexcept = delete;

GlobalsVisitor& operator=(const GlobalsVisitor&) = delete;
GlobalsVisitor& operator=(GlobalsVisitor&&) noexcept = delete;

~GlobalsVisitor() override = default;

CodeGen* cg;
bool include_implementation;

Expand Down
6 changes: 6 additions & 0 deletions hilti/toolchain/src/compiler/jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class FileGuard {
}
}

FileGuard() = default;
FileGuard(const FileGuard&) = delete;
FileGuard(FileGuard&&) = delete;
FileGuard& operator=(const FileGuard&) = delete;
FileGuard& operator=(FileGuard&&) = delete;

private:
std::vector<hilti::rt::filesystem::path> _paths;
};
Expand Down
6 changes: 6 additions & 0 deletions hilti/toolchain/src/compiler/optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class OptimizerVisitor {
virtual void collect(Node&) {}
virtual bool prune_uses(Node&) { return false; }
virtual bool prune_decls(Node&) { return false; }

OptimizerVisitor() = default;
OptimizerVisitor(const OptimizerVisitor&) = default;
OptimizerVisitor(OptimizerVisitor&&) = default;
OptimizerVisitor& operator=(const OptimizerVisitor&) = default;
OptimizerVisitor& operator=(OptimizerVisitor&&) = default;
};

struct FunctionVisitor : OptimizerVisitor, visitor::PreOrder<bool, FunctionVisitor> {
Expand Down
6 changes: 6 additions & 0 deletions hilti/toolchain/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

struct RuntimeWrapper {
~RuntimeWrapper() { hilti::rt::done(); }

RuntimeWrapper() = default;
RuntimeWrapper(const RuntimeWrapper&) = delete;
RuntimeWrapper(RuntimeWrapper&&) = delete;
RuntimeWrapper& operator=(const RuntimeWrapper&) = delete;
RuntimeWrapper& operator=(RuntimeWrapper&&) = delete;
};

int main(int argc, char** argv) {
Expand Down
5 changes: 5 additions & 0 deletions spicy/runtime/include/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct OneFilter {
hilti::rt::Resumable _resumable)
: parse(std::move(_parse)), input(std::move(_input)), resumable(std::move(_resumable)) {}

~OneFilter() = default;

OneFilter& operator=(const OneFilter&) = delete;
OneFilter& operator=(OneFilter&&) = default;

Parse1Function parse;
hilti::rt::ValueReference<hilti::rt::Stream> input;
hilti::rt::Resumable resumable;
Expand Down
Loading