Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Provide a Virtual Method Anchor for Classes in Headers #6036

Closed
iphydf opened this issue Mar 23, 2020 · 2 comments · Fixed by #6394
Closed

Provide a Virtual Method Anchor for Classes in Headers #6036

iphydf opened this issue Mar 23, 2020 · 2 comments · Fixed by #6394
Labels
C-bug The issue contains a bug report D-easy We estimate that the issue is easy to fix Good first issue This is a good issue to get started working on qTox M-architecture Category for internal architecture problems

Comments

@iphydf
Copy link
Contributor

iphydf commented Mar 23, 2020

If a class is defined in a header file and has a vtable (either it has virtual methods or it derives from classes with virtual methods), it must always have at least one out-of-line virtual method in the class. Without this, the compiler will copy the vtable and RTTI into every .o file that #includes the header, bloating .o file sizes and increasing link times.

Source: http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers

In most cases, this is just a matter of adding an explicitly defined destructor and defining it in the .cpp file.

@sudden6 sudden6 added C-bug The issue contains a bug report D-easy We estimate that the issue is easy to fix Good first issue This is a good issue to get started working on qTox M-architecture Category for internal architecture problems labels Mar 26, 2020
@brandonmosher
Copy link

I'd like to take on this issue if no one else has started yet.

@anthonybilinski
Copy link
Member

Go for it, AFAIK no one has.

sphaerophoria pushed a commit to sphaerophoria/qTox that referenced this issue Nov 10, 2021
Define at least one virtual method in polymorphic class cpp files to
improve link efficiency. Do so by defining a defaulted destructor or
another overridden virtual method in the class cpp file.
Also add explicitly defaulted copy/move constructors and assignment
operators to follow the rule of five and to avoid compiler suppression
of these functions due to the addition of a user-provided destructor.
Where neccessary, create new cpp files and add them to CMakeLists and
Testing.cmake. Set the -Wweak-vtables by default when compiling with
clang to issue warnings for new classes that do not comply with this
pattern.

See http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers.

Fixes qTox#6036.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-bug The issue contains a bug report D-easy We estimate that the issue is easy to fix Good first issue This is a good issue to get started working on qTox M-architecture Category for internal architecture problems
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants