I know about similar questions, but still would like to understand if described warning is pointless or not.
Potential duplicates could be:
- clang: no out-of-line virtual method definitions (pure abstract C++ class)
- What is the meaning of clang's -Wweak-vtables?
but I still have a feeling, this question is different.
Let's imagine that I have a base class implemented as NVI.
struct server_strategy
{
explicit server_strategy(std::string name) : name_{std::move(name)} {}
virtual ~server_strategy()=default;
zmq::message_t handle_message(zmq::message_t request)
{
// ...
}
std::string const& log_channel()const {return name_;}
private:
virtual zmq::message_t do_handle_message(zmq::message_t request) =0;
private:
const std::string name_;
};
Compiling this class makes Clang issuing the warning:
error: 'server_strategy' has no out-of-line virtual method definitions;
its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
Question: Why does =default
makes sense at all in context of virtual destructors? Don't you think that this warning is overkill in that context? I mean if I explicitly declare virtual destructor as defaulted than I probably don't want to introduce an additional .cpp file and I know that compiler is going to pick any translation unit for its implementation.
Aucun commentaire:
Enregistrer un commentaire