Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid weak-vtable warnings for classes only defined in a source file

I understand that a class class needs at least one virtual function defined in a source file (out of line), otherwise the vtable will need to be inserted into every object file.

I have the following situation:

//foo.cpp

struct Foo {
virtual int Bar() { return 1; }
virtual ~Foo() = default;
};

The clang code model in Qt Creator (4.5.2) emits a -Wweak-table warning for Foo.
Strictly speaking the warning is correct, as the vtable will be included in every translation unit. Practically, it's worthless because either way the vtable is only emitted in foo.o anyway.

How can I disable -Wweak-vtables only for classes defined in a source file?

like image 544
tstenner Avatar asked Oct 18 '25 15:10

tstenner


1 Answers

It turns out that standalone clang does the right thing by default, only the clang code model in Qt creator shows the useless warning. It's already reported as QTCREATORBUG-19741, so there's nothing more to do than wait for an updated Qt creator version.

like image 122
tstenner Avatar answered Oct 20 '25 05:10

tstenner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!