Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
USB: add pure specifiers and emit vtable#771
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Issuearduino#130 correctly identifies a newly-added method as pure virtual andfixes the declaration. However, for some reason it didn't address all ofthe other virtual methods in that same class (`PluggableUSBModule`) thatdo not define a default implementation.The only virtual method that has a default implementation is providedinline in the class interface:```c++ virtual void callback_reset() {};```These issues combined prevent the compiler from being able to emit avtable for the `PluggableUSBModule` class, thus preventing users fromcorrectly subclassing it or any one of its derived classes such as`USBCDC`, `USBHID`, `USBMIDI`, etc. Refer to the following answer onStackOverflow for a detailed explanation of the issue:https://stackoverflow.com/a/57504289/1054397This PR adds the pure specifier (`= 0`) to all of the virtual methods inthis class that do not have a default implementation. It also moves thedefault empty definition of `virtual void callback_reset()` to the classdefinition in `USB/PluggableUSBDevice.cpp` so that this class compliescompletely with the criteria for emitting a vtable.> #### Note>> The error that I was encountering prior to these changes was pretty> cryptic (from PlatformIO):>> ```txt> .pio/build/hid/src/target.cpp.o: In function `foo()':> USBHID/src/PluggableUSBHID.h:53: undefined reference to> `vtable for arduino::internal::PluggableUSBModule'> .pio/build/hid/src/target.cpp.o: In function `foo()':> foo.hpp:100: undefined reference to> `vtable for arduino::internal::PluggableUSBModule'> collect2: error: ld returned 1 exit status> *** [.pio/build/hid/firmware.elf] Error 1> ```>> Even stranger, the error would only be generated with a debug build;> i.e., the only difference in command-line arguments was the additional> CFLAGS of `-Og -g2 -ggdb2`. Without the debug flags, my project was> building without error.>> With the changes in this PR, my project now builds with and without> these additional debug flags. Further verification was performed by> testing the example sketches `Keyboard`, `KeyboardRaw`, and `Mouse`> from library `USBHID` as well as using the core `Serial` object for> ordinary USB serial I/O (`USBCDC`).
CLAassistant commentedNov 23, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Member
facchinm commentedDec 4, 2023
LGTM! Thanks! |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue#130 correctly identifies a newly-added method as pure virtual and fixes the declaration. However, for some reason it didn't address all of the other virtual methods in that same class (
PluggableUSBModule) that do not define a default implementation.The only virtual method that has a default implementation is provided inline in the class interface:
These issues combined prevent the compiler from being able to emit a vtable for the
PluggableUSBModuleclass, thus preventing users from correctly subclassing it or any one of its derived classes such asUSBCDC,USBHID,USBMIDI, etc. Refer to the following answer on StackOverflow for a detailed explanation of the issue:https://stackoverflow.com/a/57504289/1054397
This PR adds the pure specifier (
= 0) to all of the virtual methods in this class that do not have a default implementation. It also moves the default empty definition ofvirtual void callback_reset()to the class definition inUSB/PluggableUSBDevice.cppso that this class complies completely with the criteria for emitting a vtable.