From 51d7a62bee6bc14dc719c49cd688b4b5aa5dd1b0 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 5 Jan 2018 22:31:04 +0100 Subject: [PATCH] eliminate -Wweak-vtables warnings --- build.cc | 11 +++++++---- ostd/argparse.hh | 20 +++++++++++++++++++- ostd/channel.hh | 2 ++ ostd/concurrency.hh | 5 ++++- ostd/coroutine.hh | 7 +++---- ostd/format.hh | 2 ++ ostd/generic_condvar.hh | 2 +- ostd/process.hh | 4 ++++ ostd/stream.hh | 4 +++- ostd/string.hh | 2 ++ src/argparse.cc | 22 ++++++++++++++++++++++ src/channel.cc | 19 +++++++++++++++++++ src/concurrency.cc | 20 +++++++++++++++++--- src/io.cc | 5 +++++ src/process.cc | 8 ++++++++ src/string.cc | 8 ++++++++ 16 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 src/argparse.cc create mode 100644 src/channel.cc diff --git a/build.cc b/build.cc index d8b18c0..f843677 100644 --- a/build.cc +++ b/build.cc @@ -28,6 +28,9 @@ namespace fs = ostd::filesystem; #include "src/io.cc" #include "src/process.cc" #include "src/filesystem.cc" +#include "src/channel.cc" +#include "src/string.cc" +#include "src/argparse.cc" #define OSTD_GEN_UNICODE_INCLUDE #include "gen_unicode.cc" @@ -60,15 +63,15 @@ static fs::path OSTD_SHARED_LIB = "libostd.so"; static fs::path OSTD_STATIC_LIB = "libostd.a"; static std::string DEFAULT_CXXFLAGS = "-std=c++1z -I. -O2 -Wall -Wextra " - "-Wshadow -Wold-style-cast"; + "-Wshadow -Wold-style-cast -fPIC"; static std::string DEFAULT_LDFLAGS = "-pthread"; -static std::string DEFAULT_ASFLAGS = ""; +static std::string DEFAULT_ASFLAGS = "-fPIC"; static std::string DEBUG_CXXFLAGS = "-g"; -static std::string SHARED_CXXFLAGS = "-fPIC"; +static std::string SHARED_CXXFLAGS = ""; static std::string SHARED_LDFLAGS = "-shared"; -static std::string SHARED_ASFLAGS = "-fPIC"; +static std::string SHARED_ASFLAGS = ""; /* DO NOT CHANGE PAST THIS POINT */ diff --git a/ostd/argparse.hh b/ostd/argparse.hh index ab63b67..4c713ee 100644 --- a/ostd/argparse.hh +++ b/ostd/argparse.hh @@ -44,6 +44,9 @@ namespace ostd { struct arg_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~arg_error(); + template arg_error(string_range fmt, A const &...args): arg_error(format(appender(), fmt, args...).get()) @@ -101,7 +104,7 @@ struct arg_description { friend struct arg_group; /** @brief The base class contains no data. */ - virtual ~arg_description() {} + virtual ~arg_description(); /** @brief Gets an ostd::arg_type for the class. */ virtual arg_type type() const noexcept = 0; @@ -136,6 +139,9 @@ protected: * It's not instantiated directly. */ struct arg_argument: arg_description { + /* empty, for vtable placement */ + virtual ~arg_argument(); + /** @brief Sets the help for the argument. * * The help string is stored internally. Returns itself. @@ -226,6 +232,9 @@ struct arg_optional: arg_argument { friend struct arg_group; friend struct arg_mutually_exclusive_group; + /* empty, for vtable placement */ + virtual ~arg_optional(); + /** @brief Gets the argument class type (ostd::arg_type). * * The value is always `OPTIONAL`. @@ -519,6 +528,9 @@ struct arg_positional: arg_argument { friend struct basic_arg_parser; friend struct arg_description_container; + /* empty, for vtable placement */ + virtual ~arg_positional(); + /** @brief Gets the argument class type (ostd::arg_type). * * The value is always `POSITIONAL`. @@ -662,6 +674,9 @@ private: struct arg_mutually_exclusive_group: arg_description { friend struct arg_description_container; + /* empty, for vtable placement */ + virtual ~arg_mutually_exclusive_group(); + /** @brief Gets the argument class type (ostd::arg_type). * * The value is always `MUTUALLY_EXCLUSIVE_GROUP`. @@ -866,6 +881,9 @@ struct arg_group: arg_description, arg_description_container { template friend struct basic_arg_parser; + /* empty, for vtable placement */ + virtual ~arg_group(); + /** @brief Gets the argument class type (ostd::arg_type). * * The value is always `GROUP`. diff --git a/ostd/channel.hh b/ostd/channel.hh index 6750272..e606ab9 100644 --- a/ostd/channel.hh +++ b/ostd/channel.hh @@ -35,6 +35,8 @@ namespace ostd { /** @brief Thrown when manipulating a channel that has been closed. */ struct channel_error: std::logic_error { using std::logic_error::logic_error; + /* empty, for vtable placement */ + virtual ~channel_error(); }; /** @brief A thread-safe message queue. diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index f3f0025..b9c2b30 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -236,7 +236,7 @@ protected: public: /** @brief Does nothing, this base class is empty. */ - virtual ~scheduler() {} + virtual ~scheduler(); scheduler(scheduler const &) = delete; scheduler(scheduler &&) = delete; @@ -553,6 +553,9 @@ namespace detail { csched_task &operator=(csched_task const &) = delete; csched_task &operator=(csched_task &&) = delete; + /* empty, for vtable placement */ + virtual ~csched_task(); + template csched_task(F &&f, SA &&sa): p_func(std::forward(f)) { if (!p_func) { diff --git a/ostd/coroutine.hh b/ostd/coroutine.hh index 22df6a0..9b33bd8 100644 --- a/ostd/coroutine.hh +++ b/ostd/coroutine.hh @@ -56,6 +56,8 @@ namespace ostd { */ struct coroutine_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~coroutine_error(); }; /** @brief An encapsulated context any coroutine-type inherits from. @@ -91,10 +93,7 @@ protected: * stack is freed (if present) using the same stack allocator it was * allocated with. */ - virtual ~coroutine_context() { - unwind(); - free_stack(); - } + virtual ~coroutine_context(); coroutine_context(coroutine_context const &) = delete; diff --git a/ostd/format.hh b/ostd/format.hh index 3ef7720..193c9d9 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -57,6 +57,8 @@ enum format_flags { /** @brief Thrown when format string does not properly match the arguments. */ struct format_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~format_error(); }; struct format_spec; diff --git a/ostd/generic_condvar.hh b/ostd/generic_condvar.hh index 48ac09e..87a26ce 100644 --- a/ostd/generic_condvar.hh +++ b/ostd/generic_condvar.hh @@ -25,7 +25,7 @@ namespace ostd { namespace detail { struct cond_iface { cond_iface() {} - virtual ~cond_iface() {} + virtual ~cond_iface(); virtual void notify_one() = 0; virtual void notify_all() = 0; virtual void wait(std::unique_lock &) = 0; diff --git a/ostd/process.hh b/ostd/process.hh index 30921d0..be80108 100644 --- a/ostd/process.hh +++ b/ostd/process.hh @@ -34,6 +34,8 @@ namespace ostd { /** @brief Thrown on errors in ostd::split_args(). */ struct word_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~word_error(); }; namespace detail { @@ -81,6 +83,8 @@ Sink &&split_args(Sink &&out, string_range str) { /** @brief Thrown on errors in ostd::subprocess. */ struct subprocess_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~subprocess_error(); }; /** @brief The mode used for standard streams in ostd::subprocess. diff --git a/ostd/stream.hh b/ostd/stream.hh index ce4fede..6dd2dc5 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -90,6 +90,8 @@ struct stream_range; /** @brief Thrown on stream errors. */ struct stream_error: std::system_error { using std::system_error::system_error; + /* empty, for vtable placement */ + virtual ~stream_error(); }; template> @@ -105,7 +107,7 @@ struct stream { using offset_type = stream_off_t; /** @brief Does nothing by default. */ - virtual ~stream() {} + virtual ~stream(); /** @brief Closes the stream. * diff --git a/ostd/string.hh b/ostd/string.hh index 3fe2b60..e57ca2a 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -747,6 +747,8 @@ namespace utf { /** @brief Thrown on UTF-8 decoding failure. */ struct utf_error: std::runtime_error { using std::runtime_error::runtime_error; + /* empty, for vtable placement */ + virtual ~utf_error(); }; /* @brief Get the Unicode code point for a UTF-8 sequence. diff --git a/src/argparse.cc b/src/argparse.cc new file mode 100644 index 0000000..4859a2a --- /dev/null +++ b/src/argparse.cc @@ -0,0 +1,22 @@ +/* Argparse implementation details. + * + * This file is part of libostd. See COPYING.md for futher information. + */ + +#include "ostd/argparse.hh" + +namespace ostd { + +/* place the vtables in here */ + +arg_error::~arg_error() {} + +arg_description::~arg_description() {} +arg_argument::~arg_argument() {} +arg_optional::~arg_optional() {} +arg_positional::~arg_positional() {} + +arg_mutually_exclusive_group::~arg_mutually_exclusive_group() {} +arg_group::~arg_group() {} + +} /* namespace ostd */ diff --git a/src/channel.cc b/src/channel.cc new file mode 100644 index 0000000..fc2cfa5 --- /dev/null +++ b/src/channel.cc @@ -0,0 +1,19 @@ +/* Channel implementation bits. + * + * This file is part of libostd. See COPYING.md for futher information. + */ + +#include "ostd/generic_condvar.hh" +#include "ostd/channel.hh" + +namespace ostd { + +/* place the vtable in here */ +channel_error::~channel_error() {} + +namespace detail { + /* vtable placement for generic_condvar */ + cond_iface::~cond_iface() {} +} /* namespace detail */ + +} /* namespace ostd */ diff --git a/src/concurrency.cc b/src/concurrency.cc index 1f5e163..d73baea 100644 --- a/src/concurrency.cc +++ b/src/concurrency.cc @@ -6,10 +6,24 @@ #include "ostd/concurrency.hh" namespace ostd { + +/* place the vtable in here */ +coroutine_error::~coroutine_error() {} + +/* non-inline for vtable placement */ +coroutine_context::~coroutine_context() { + unwind(); + free_stack(); +} + namespace detail { + /* place the vtable here, derived from coroutine_context */ + csched_task::~csched_task() {} -OSTD_EXPORT scheduler *current_scheduler = nullptr; -OSTD_EXPORT thread_local csched_task *current_csched_task = nullptr; - + OSTD_EXPORT scheduler *current_scheduler = nullptr; + OSTD_EXPORT thread_local csched_task *current_csched_task = nullptr; } /* namespace detail */ + +scheduler::~scheduler() {} + } /* namespace ostd */ diff --git a/src/io.cc b/src/io.cc index 15a7396..7372358 100644 --- a/src/io.cc +++ b/src/io.cc @@ -8,10 +8,15 @@ #include #include +#include "ostd/stream.hh" #include "ostd/io.hh" namespace ostd { +/* place the vtable in here */ +stream_error::~stream_error() {} +stream::~stream() {} + static char const *filemodes[] = { "rb", "wb", "ab", "rb+", "wb+", "ab+" }; diff --git a/src/process.cc b/src/process.cc index d3a7e55..21f83f2 100644 --- a/src/process.cc +++ b/src/process.cc @@ -12,3 +12,11 @@ #else # error "Unsupported platform" #endif + +namespace ostd { + +/* place the vtable in here */ +word_error::~word_error() {} +subprocess_error::~subprocess_error() {} + +} /* namespace ostd */ diff --git a/src/string.cc b/src/string.cc index ed514ae..7c7b4bb 100644 --- a/src/string.cc +++ b/src/string.cc @@ -6,10 +6,14 @@ #include #include #include "ostd/string.hh" +#include "ostd/format.hh" namespace ostd { namespace utf { +/* place the vtable in here */ +utf_error::~utf_error() {} + constexpr char32_t MaxCodepoint = 0x10FFFF; namespace detail { @@ -461,4 +465,8 @@ int case_compare(u32string_range s1, u32string_range s2) noexcept { } } /* namespace utf */ + +/* place the vtable in here */ +format_error::~format_error() {} + } /* namespace ostd */