Skip to content

"Wrapped" has virtual functions so it should have a virtual destructor. - #998

Merged
Faless merged 1 commit into
godotengine:masterfrom
asmaloney:fix-virtual-destructor
Jan 19, 2023
Merged

Faless merged 1 commit into
godotengine:masterfrom
asmaloney:fix-virtual-destructor

Conversation

@asmaloney

Copy link
Copy Markdown
Contributor

Deleting an object through a pointer to a base class is undefined behaviour unless the destructor in the base class is virtual.

@asmaloney
asmaloney requested a review from a team as a code owner January 18, 2023 00:30
@Calinou Calinou added the bug This has been identified as a bug label Jan 18, 2023

@Faless Faless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See style comment, looking good otherwise 👍 🏆

Comment thread include/godot_cpp/classes/wrapped.hpp Resolved
Comment thread src/classes/wrapped.cpp Resolved
@asmaloney

Copy link
Copy Markdown
Contributor Author

@Faless I generally don't put implementations in library headers, but I guess this project doesn't make that distinction.

Why not default? Is not using it part of the godot style somewhere?

@Faless

Faless commented Jan 19, 2023 •

Copy link
Copy Markdown
Contributor

Why not default? Is not using it part of the godot style somewhere?

More or less, it's not used anywhere beside few very rare exceptions, and even then, always in the header file.

@asmaloney

Copy link
Copy Markdown
Contributor Author

OK. I think it's better style because it directly communicates intent, but 🤷 😄

@Faless

Faless commented Jan 19, 2023 •

Copy link
Copy Markdown
Contributor

OK. I think it's better style because it directly communicates intent, but

I honestly don't mind too much as long as it's in the header file so I don't have to open the cpp file just to find out it's the default one.

As per = default vs {} I actually find it weird that there are those few exceptions in the godot codebase since I thought we had a formal check for that, but it doesn't seem to be the case (CC @akien-mga ).

@akien-mga

Copy link
Copy Markdown
Member

As per = default vs {} I actually find it weird that there are those few exceptions in the godot codebase since I thought we had a formal check for that, but it doesn't seem to be the case (CC @akien-mga ).

We predominantly use {}, so unless there's a clear advantage to using = default;, I would keep {} for now for consistency.

If there is a significant advantage to moving to = default;, this would be worth a proposal and changing across the whole Godot codebase(s).

Deleting an object through a pointer to a base class is undefined behaviour unless the destructor in the base class is virtual.
@asmaloney
asmaloney force-pushed the fix-virtual-destructor branch from f90f6a8 to 5dd2928 Compare January 19, 2023 10:57
@Faless
Faless merged commit 2eb375e into godotengine:master Jan 19, 2023
@Faless

Faless commented Jan 19, 2023

Copy link
Copy Markdown
Contributor

Thanks!

@asmaloney
asmaloney deleted the fix-virtual-destructor branch January 19, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This has been identified as a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants