Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add explicit virtual destructor in order to fix linker issues #13756

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

Swiftb0y
Copy link
Member

May fix #13755

@github-actions github-actions bot added the build label Oct 12, 2024
@daschuer
Copy link
Member

For my understanding, without explicit declaration, the implicit default destructor is not virtual. This is an issue when a class is deleted by its base class.
There are not much cases where this is desired so overriding the destructor is kind of mandatory.

Can we add a CI check for this?

@daschuer
Copy link
Member

daschuer commented Oct 12, 2024

I have no explanation for the issue though, the AutoFileReloader is used as a member variable where this issue is not relevant.

And the ~QObject is virtual so this is even more not an issue here.

@daschuer
Copy link
Member

Since 707a08f fixes the issue, can we close this?

@Swiftb0y
Copy link
Member Author

Swiftb0y commented Oct 13, 2024

Can we add a CI check for this?

I don't think so. I would expect the compiler to catch this by itself already.

And the ~QObject is virtual so this is even more not an issue here.

Yeah I agree. The implicit destructor was a red herring. Nevertheless, its probably better practice to have it declared and defined in the .cpp (because it can't benefit from the implicitly generated one in the header).

Since 707a08f fixes the issue, can we close this?

That commit is part of this PR. So closing PR doesn't make sense.

@daschuer
Copy link
Member

So closing PR doesn't make sense.

Oh yes, I see.

autofilereloader.cpp is not used in mixxx-lib and can be removed here:

src/util/autofilereloader.cpp

Nevertheless, its probably better practice to have it declared and defined in the .cpp (because it can't benefit from the implicitly generated one in the header).

Why? For my understanding it is better to remove the destructor again and allow the Compiler to inline it and finally optimize it away.

@@ -2792,6 +2792,8 @@ if(QML)
# The following sources need to be in this target to get QML_ELEMENT properly interpreted
src/control/controlmodel.cpp
src/control/controlsortfiltermodel.cpp
# needed for qml/qmlautoreload.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally don't have such comments, remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be confused on where this comes from (since the remaining files in the module all live in the qml directory), so I figured it would be better to make clear why this is necessary. I can remove if you disagree with the exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'm using autoreloader in #13082

Copy link
Member Author

@Swiftb0y Swiftb0y Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the headsup. well then it needs to be linked in both anyways. That discussion is therefore resolved.

@Swiftb0y
Copy link
Member Author

Why? For my understanding it is better to remove the destructor again and allow the Compiler to inline it and finally optimize it away.

It can't inline the dtor though because its virtual. It may if the class was declared final, but even then only in certain cirumstances. Since its a QObject it will also have to call the QObject dtor at some point, which for sure can't be inlined because the PIMPL pattern.

I would fully agree with your conclusion if this was TriviallyDestructible, but with QObjects, the very opposite is the case (they always have a virtual destructor). So the compiler will likely declare the function as inline in the header and let the linker deduplicate it. So in the binary, its effectively as if it was always in the translation unit. So the hope that the compiler can optimize much here doesn't apply.

I will try to reproduce in compiler explorer, but I don't have time right now.

@Swiftb0y Swiftb0y requested a review from daschuer October 13, 2024 21:19
Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explaining. LGTM

Our library layout is still not optimal, but let's merge this now make main build again.

@daschuer daschuer merged commit 832f740 into mixxxdj:main Oct 14, 2024
13 checks passed
@Swiftb0y Swiftb0y deleted the fix/gh13755-autofilereloader-linking branch October 14, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'undefined reference' after autofilereloader commit
3 participants