3

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?

tstenner
  • 10,080
  • 10
  • 57
  • 92

2 Answers2

3

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.

tstenner
  • 10,080
  • 10
  • 57
  • 92
1

Not really sure, but where I work, we have some practices for disabling warnings in localized sources.

Under windows:

#pragma warning(push)
#pragma warning(disable : 4820)
//Rest of your includes (cstdio, vector...)
#pragma warning(pop) //For /Wall

Under gcc like:

#pragma GCC diagnostic push 
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
//Rest of your includes (cstdio, vector...)
#pragma GCC diagnostic pop
Sandburg
  • 757
  • 15
  • 28