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 is about =default
keyword and not about where virtual destructor's impl will finally land!
- 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. It'd be handy to let library authors avoid these warnings, but switching to defaulted virtual destructors instead of inline implementation, but it turns out that library authors have no other choice than deal with pragmas and conditional define macros which compiler is being used to disable these warnings.