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

Adafruit_GFX destructor #236

Open
ArturZiolkowski1999 opened this issue Mar 17, 2022 · 1 comment
Open

Adafruit_GFX destructor #236

ArturZiolkowski1999 opened this issue Mar 17, 2022 · 1 comment

Comments

@ArturZiolkowski1999
Copy link

when deleting Adafruit_SSD1306 object, i've got this warning:
warning: deleting object of polymorphic class type 'Adafruit_SSD1306' which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor].
I suggest to create Adafruit_GFX destructor.

@BillyDonahue
Copy link
Contributor

BillyDonahue commented Mar 18, 2022

This would make apps take up more space than they do now.
The warning is a false positive.

Adafruit_GFX objects are trivially destructible. There's no reason to declare a user-defined destructor, other than to maybe mark it as virtual. All data members in an Adafruit_GFX are trivial.

Adafruit_GFX objects are rarely held by pointers or destroyed by apps. They're just declared as static-duration namespace-scope objects typically, and used in setup() and loop() functions. There's no destructor call, as Arduino apps have no exit sequence.

Because the sketch doesn't actually destroy it, the linker can currently optimize the destructor out.

But if it's virtual, the destructor becomes part of the type's __vtbl. So at that point there's a reference pinning that destructor's address to the final executable and it can't be optimized away. I believe this will cause executables to grow slightly in size. -W warnings are nice to have, but size-constrained apps shouldn't have to take up more RAM to silence a false positive.

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

No branches or pull requests

2 participants