adafruit / adafruit/Adafruit_nRF52_Arduino
Cannot generate `typeinfo` for `HardwareSerial` without at least one method default defined
- Dominant language
- C
- Stars
- 699
- Forks
- 570
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Yes. In order to generate `typeinfo` for the `HardwareSerial` class (even with `-frtti` enabled), there must be a default empty definition somewhere of the `HardwareSerial::begin(unsigned int)` method (at least). I chose this one arbitrarily. Without these `typeinfo` symbols I can't `dynamic_cast` anything involving `HardwareSerial`.
**Describe the solution you'd like**
Add a `HardwareSerial.cpp` file with an empty definition of the previously mentioned `begin` method. Unfortunately the compiler won't take the hint from `HardwareSerial.h` in which
```cpp
class HardwareSerial : public Stream
{
public:
virtual void begin(unsigned long);
};
```
becomes
```cpp
class HardwareSerial : public Stream
{
public:
virtual void begin(unsigned long baudrate) {} // Now it's defined
};
```
because this is "inline" and apparently doesn't qualify as a sufficient indicator to allow RTTI to generate the `typeinfo`.
**Describe alternatives you've considered**
I've simply added my explicit default definition of `HardwareSerial::begin(unsigned int)` in another source file. This works, but it feels like this should be a part of the library because it serves as an abstract class.
**Additional context**
This issue isn't terribly important, but I will say that the ESP32 and ItsyBitsyM4 frameworks don't run into this problem at all. And it's an easy fix.
I can also submit the fix myself.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the HardwareSerial declaration shown in HardwareSerial.h and compare the stated unsigned long signature with the requested definition. Add the proposed HardwareSerial.cpp implementation, then verify that RTTI typeinfo is generated and dynamic_cast involving HardwareSerial works as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100