From 99b9121e2158603372c7313400283b622e6754d8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 31 Oct 2021 13:28:41 +0200 Subject: [PATCH] Mark constructors and destructors as default where appropriate --- source/core/application.h | 4 ++-- source/core/getopt.h | 14 +++++++------- source/core/maputils.h | 2 +- source/core/refptr.h | 4 ++-- source/core/systemerror.h | 2 +- source/core/variant.h | 4 ++-- source/fs/dir.h | 2 +- source/fs/path.cpp | 3 --- source/fs/path.h | 2 +- source/fs/stat.h | 2 +- source/fs/stat_private.h | 2 +- source/io/file.h | 4 ++-- source/io/mode.h | 2 +- source/io/seekable.h | 4 ++-- source/io/zlibcompressed.h | 2 +- source/stringcodec/codec.h | 8 ++++---- source/stringcodec/except.h | 6 +++--- source/strings/fmt.h | 2 +- source/strings/lexicalcast.h | 4 ++-- source/strings/regex.h | 2 +- source/strings/regmatch.h | 2 +- source/time/timedelta.h | 2 +- source/time/timestamp.h | 2 +- 23 files changed, 39 insertions(+), 42 deletions(-) diff --git a/source/core/application.h b/source/core/application.h index 40215ef..8ff286f 100644 --- a/source/core/application.h +++ b/source/core/application.h @@ -18,7 +18,7 @@ protected: protected: Starter(); public: - virtual ~Starter() { } + virtual ~Starter() = default; virtual Application *create_app(int, char **) = 0; }; @@ -38,7 +38,7 @@ private: protected: Application(const std::string & = std::string()); public: - virtual ~Application() { } + virtual ~Application() = default; /** Constructs an instance of the registered application class and runs it. If the application throws a usage_error, a help message is printed. The diff --git a/source/core/getopt.h b/source/core/getopt.h index a1208f4..5c21ccb 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -17,7 +17,7 @@ private: public: usage_error(const std::string &w, const std::string &h = std::string()): std::runtime_error(w), help_(h) { } - ~usage_error() throw() { } + virtual ~usage_error() throw() = default; const char *help() const throw() { return help_.c_str(); } }; @@ -72,9 +72,9 @@ public: class Option { protected: - Option() { } + Option() = default; public: - virtual ~Option() { } + virtual ~Option() = default; /// Sets help text for the option. virtual Option &set_help(const std::string &) = 0; @@ -92,9 +92,9 @@ public: class Argument { protected: - Argument() { } + Argument() = default; public: - virtual ~Argument() { } + virtual ~Argument() = default; virtual Argument &set_help(const std::string &) = 0; }; @@ -103,9 +103,9 @@ private: class Store { protected: - Store() { } + Store() = default; public: - virtual ~Store() { } + virtual ~Store() = default; virtual Store *clone() const = 0; diff --git a/source/core/maputils.h b/source/core/maputils.h index 88f47cd..7eae134 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -47,7 +47,7 @@ public: runtime_error(make_what(typeid(T), MapUtilsInternal::stringify_key(k))) { } - virtual ~key_error() throw() { } + virtual ~key_error() throw() = default; private: static std::string make_what(const std::type_info &, const std::string &); diff --git a/source/core/refptr.h b/source/core/refptr.h index 6285d0e..21da15d 100644 --- a/source/core/refptr.h +++ b/source/core/refptr.h @@ -35,7 +35,7 @@ private: RefCounts *counts = 0; public: - RefPtr() { } + RefPtr() = default; RefPtr(T *d): data(d), counts(data ? new RefCounts : 0) { incref(); } private: RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } @@ -106,7 +106,7 @@ private: RefCounts *counts = 0; public: - WeakPtr() { } + WeakPtr() = default; private: WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } diff --git a/source/core/systemerror.h b/source/core/systemerror.h index c6b516a..d0a5634 100644 --- a/source/core/systemerror.h +++ b/source/core/systemerror.h @@ -14,7 +14,7 @@ private: public: system_error(const std::string &, int = -1); system_error(const std::string &, const std::string &); - virtual ~system_error() throw() { } + virtual ~system_error() throw() = default; int code() const throw() { return code_; } diff --git a/source/core/variant.h b/source/core/variant.h index 05a8139..1ad086e 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -12,7 +12,7 @@ class type_mismatch: public std::runtime_error { public: type_mismatch(const std::type_info &, const std::type_info &); - ~type_mismatch() throw() { } + virtual ~type_mismatch() throw() = default; }; @@ -53,7 +53,7 @@ private: StoreBase *store = 0; public: - Variant() { } + Variant() = default; template Variant(const T &v): store(new Store::type>(v)) { } Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } diff --git a/source/fs/dir.h b/source/fs/dir.h index c0a1c74..fa2793a 100644 --- a/source/fs/dir.h +++ b/source/fs/dir.h @@ -13,7 +13,7 @@ class not_a_directory: public std::runtime_error { public: not_a_directory(const Path &); - virtual ~not_a_directory() throw() { } + virtual ~not_a_directory() throw() = default; }; /// Creates a directory diff --git a/source/fs/path.cpp b/source/fs/path.cpp index adf376f..0e86600 100644 --- a/source/fs/path.cpp +++ b/source/fs/path.cpp @@ -17,9 +17,6 @@ inline bool is_windows_drive(const string &p) namespace Msp { namespace FS { -Path::Path() -{ } - Path::Path(const string &p) { if(p.empty()) diff --git a/source/fs/path.h b/source/fs/path.h index 9cc0dc2..30fe683 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -70,7 +70,7 @@ private: PositionArray separators; public: - Path(); + Path() = default; Path(const std::string &); Path(const char *p): Path(std::string(p)) { } diff --git a/source/fs/stat.h b/source/fs/stat.h index 00e3eb9..d23a8e8 100644 --- a/source/fs/stat.h +++ b/source/fs/stat.h @@ -42,7 +42,7 @@ private: Private *priv = 0; public: - Stat() { } + Stat() = default; Stat(const Stat &); Stat &operator=(const Stat &); ~Stat(); diff --git a/source/fs/stat_private.h b/source/fs/stat_private.h index 60438a2..a6da473 100644 --- a/source/fs/stat_private.h +++ b/source/fs/stat_private.h @@ -11,7 +11,7 @@ struct Stat::Private UserID owner_id = INVALID_UID; GroupID group_id = INVALID_GID; - Private(); + Private() = default; Private(const Private &); ~Private(); diff --git a/source/io/file.h b/source/io/file.h index aeac6c8..36f3770 100644 --- a/source/io/file.h +++ b/source/io/file.h @@ -15,14 +15,14 @@ class file_not_found: public std::runtime_error { public: file_not_found(const std::string &fn): std::runtime_error(fn) { } - ~file_not_found() throw() { } + virtual ~file_not_found() throw() = default; }; class file_already_exists: public std::runtime_error { public: file_already_exists(const std::string &fn): std::runtime_error(fn) { } - ~file_already_exists() throw() { } + virtual ~file_already_exists() throw() = default; }; diff --git a/source/io/mode.h b/source/io/mode.h index 0f7bb4f..a643a7f 100644 --- a/source/io/mode.h +++ b/source/io/mode.h @@ -34,7 +34,7 @@ class invalid_access: public std::logic_error { public: invalid_access(Mode); - ~invalid_access() throw() { } + virtual ~invalid_access() throw() = default; }; } // namespace IO diff --git a/source/io/seekable.h b/source/io/seekable.h index 99915d8..68454d0 100644 --- a/source/io/seekable.h +++ b/source/io/seekable.h @@ -24,14 +24,14 @@ class bad_seek: public std::runtime_error { public: bad_seek(SeekOffset, SeekType); - virtual ~bad_seek() throw() { } + virtual ~bad_seek() throw() = default; }; class Seekable: public Base { protected: - Seekable() { } + Seekable() = default; public: /** Changes the read/write offset. Returns the new offset. */ diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index f31bb23..fb12d61 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -16,7 +16,7 @@ private: public: zlib_error(const std::string &, int); - ~zlib_error() throw() { } + virtual ~zlib_error() throw() = default; int code() const throw() { return code_; } }; diff --git a/source/stringcodec/codec.h b/source/stringcodec/codec.h index efa1657..f434ed8 100644 --- a/source/stringcodec/codec.h +++ b/source/stringcodec/codec.h @@ -43,7 +43,7 @@ public: Encoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { } public: - virtual ~Encoder() { } + virtual ~Encoder() = default; /** Encodes a single unicode character. If the character can't be represented in this encoding, error() should be called. */ @@ -94,7 +94,7 @@ public: Decoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { } public: - virtual ~Decoder() { } + virtual ~Decoder() = default; /** Decodes a single character from a string. The iterator is advanced to the next character. For stateful codecs, -1 may be returned if a @@ -131,9 +131,9 @@ public: }; protected: - Codec() { } + Codec() = default; public: - virtual ~Codec() { } + virtual ~Codec() = default; /** Returns the name of the encoding handled by this codec. */ virtual const char *get_name() const = 0; diff --git a/source/stringcodec/except.h b/source/stringcodec/except.h index 6e25666..a1126e7 100644 --- a/source/stringcodec/except.h +++ b/source/stringcodec/except.h @@ -14,7 +14,7 @@ class codec_error: public std::runtime_error { public: codec_error(const std::string &w): std::runtime_error(w) { } - virtual ~codec_error() throw() { } + virtual ~codec_error() throw() = default; }; @@ -25,7 +25,7 @@ class invalid_character: public codec_error { public: invalid_character(unichar, const std::string &); - virtual ~invalid_character() throw() { } + virtual ~invalid_character() throw() = default; }; @@ -36,7 +36,7 @@ class invalid_sequence: public codec_error { public: invalid_sequence(const std::string::const_iterator &, const std::string::const_iterator &, const std::string &); - virtual ~invalid_sequence() throw() { } + virtual ~invalid_sequence() throw() = default; private: std::string format_sequence(const std::string::const_iterator &, const std::string::const_iterator &); diff --git a/source/strings/fmt.h b/source/strings/fmt.h index 98e7e64..3c1db9d 100644 --- a/source/strings/fmt.h +++ b/source/strings/fmt.h @@ -11,7 +11,7 @@ class format_error: public std::logic_error { public: format_error(const std::string &w): std::logic_error(w) { } - virtual ~format_error() throw() { } + virtual ~format_error() throw() = default; }; diff --git a/source/strings/lexicalcast.h b/source/strings/lexicalcast.h index 5d58080..0c5f0a3 100644 --- a/source/strings/lexicalcast.h +++ b/source/strings/lexicalcast.h @@ -16,7 +16,7 @@ class lexical_error: public std::runtime_error { public: lexical_error(const std::string &w): runtime_error(w) { } - virtual ~lexical_error() throw() { } + virtual ~lexical_error() throw() = default; }; @@ -27,7 +27,7 @@ class format_mismatch: public lexical_error { public: format_mismatch(const std::string &w): lexical_error(w) { } - virtual ~format_mismatch() throw() { } + virtual ~format_mismatch() throw() = default; }; diff --git a/source/strings/regex.h b/source/strings/regex.h index e830c5b..ed53009 100644 --- a/source/strings/regex.h +++ b/source/strings/regex.h @@ -11,7 +11,7 @@ class bad_regex: public std::logic_error { public: bad_regex(const std::string &, const std::string &, const std::string::const_iterator &); - virtual ~bad_regex() throw() { } + virtual ~bad_regex() throw() = default; private: std::string make_where(const std::string &, const std::string::const_iterator &); diff --git a/source/strings/regmatch.h b/source/strings/regmatch.h index 0858e5a..48f65c6 100644 --- a/source/strings/regmatch.h +++ b/source/strings/regmatch.h @@ -40,7 +40,7 @@ private: public: /** Constructs a RegMatch representing a non-match. */ - RegMatch() { } + RegMatch() = default; /** Constructs a new RegMatch from a string and groups. The length and str members of each group are computed and need not be set. Intended to be used diff --git a/source/time/timedelta.h b/source/time/timedelta.h index 3326835..a3e62f1 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -19,7 +19,7 @@ private: public: /** Constructs a zero TimeDelta. */ - TimeDelta() { } + TimeDelta() = default; /** Constructs a TimeDelta from a plain number. The purpose of this is to allow serialization together with the raw() function. */ diff --git a/source/time/timestamp.h b/source/time/timestamp.h index d16bb06..2a5c4e1 100644 --- a/source/time/timestamp.h +++ b/source/time/timestamp.h @@ -21,7 +21,7 @@ private: public: /** Construct a TimeStamp that represents an arbitarily distant point in the past. It's guaranteed to be less than any valid timestamp. */ - TimeStamp() { } + TimeStamp() = default; /** Constructs a TimeStamp from a plain number. The purpose of this is to allow serialization together with the raw() function. */ -- 2.43.0