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

Resolve 3301 compiler warnings #645

Merged
merged 13 commits into from
Nov 26, 2024
Merged

Resolve 3301 compiler warnings #645

merged 13 commits into from
Nov 26, 2024

Conversation

jengelh
Copy link
Contributor

@jengelh jengelh commented Nov 3, 2024

Pull Request Type

  • Build and Dependency changes

Description

Compiler warnings point out qualitative issues with the code. gcc emits roughly 3860 warnings on Linux-amd64.
This batch addresses the top two categories,

scripts/Y2K.cpp:467:5: warning: deleting object of polymorphic class type "LevelScript_0000" which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor]
      467 |     delete ((LevelScript_0000 *)ptr);
scripts/LEVEL0.cpp:1036:27: warning: unused variable "event_data" [-Wunused-variable]

Checklist

  • I have tested my changes locally and verified that they work as intended.
  • I have reviewed the changes to ensure they do not introduce any unnecessary complexity or duplicate code.
  • I understand that by submitting this pull request, I am agreeing to license my contributions under the project's license.

scripts/Y2K.cpp:467:5: warning: deleting object of polymorphic class type
"LevelScript_0000" which has non-virtual destructor might cause undefined
behavior [-Wdelete-non-virtual-dtor]
  467 |     delete ((LevelScript_0000 *)ptr);
Devirtualization is an optimization in the generated assembly: when a
class C is polymorphic but also final, ``((C *)ptr)->func()`` can be
turned from an indirect into a static call.
Some classes did set it to nullptr and others did not.
For the sake of consistency, initialize it explicitly everywhere.
scripts/LEVEL0.cpp:1036:27: warning: unused variable "event_data" [-Wunused-variable]
and a lot more.
@jengelh jengelh changed the title Resolve 2100 compiler warnings Resolve 3301 compiler warnings Nov 4, 2024
@jengelh jengelh force-pushed the master branch 3 times, most recently from cbaacef to 9ba0037 Compare November 4, 2024 10:58
Descent3/multi_dll_mgr.cpp:974:43: warning: deleting "void*" is
undefined [-Wdelete-incomplete]

(``delete`` requires that types are _complete_, so as to find the
right destructor to call; ``void`` is incomplete by definition.)
Copy link
Member

@Lgt2x Lgt2x left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to solve warnings, that's very appreciated. Splitting in multiple commits will help if we ever need to revert something that unexpectedly causes mayhem. In the meantime, I did not see any change that could be a problem. Runtime is fine too.

Descent3/Controls.cpp Show resolved Hide resolved
@Lgt2x Lgt2x merged commit 836dd4d into DescentDevelopers:main Nov 26, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants