Commit e81cc97
committed
USB: add pure specifiers and emit vtable
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:
```c++
virtual void callback_reset() {};
```
These issues combined prevent the compiler from being able to emit a
vtable for the `PluggableUSBModule` class, thus preventing users from
correctly subclassing it or any one of its derived classes such as
`USBCDC`, `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 of `virtual void callback_reset()` to the class
definition in `USB/PluggableUSBDevice.cpp` so that this class complies
completely 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`).1 parent 7b95100 commit e81cc97
File tree
2 files changed
+23
-9
lines changed- cores/arduino/USB
2 files changed
+23
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
| |||
0 commit comments