-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
StreamConstPtr: disallow passing a String temporary #8410
Conversation
(warning: deleting object of abstract class type 'Stream' which has non-virtual destructor will cause undefined behavior [-Wdelete-non-virtual-dtor])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer works
StreamConstPtr test{String("test")}; // String is destroyed next line, can't access it's contents
StreamConstPtr test{"test"}; // implicitly creating String{"test"}, same lifetime as above
This was allowed, but no longer is
StreamConstPtr{"test"}.available(); // ...since we are technically in the same 'expression', still and StreamConstPtr itself is a temporary?
@@ -61,6 +61,7 @@ class Stream: public Print { | |||
virtual int peek() = 0; | |||
|
|||
Stream() {} | |||
virtual ~Stream() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commitlog added in OP
* StreamConstPtr: prevent from passing a temporary String instance * unconditionally allow progmem chars * missing virtual destructor in Stream (warning: deleting object of abstract class type 'Stream' which has non-virtual destructor will cause undefined behavior [-Wdelete-non-virtual-dtor])
Unless using it like this:
using
auto var = StreamConstPtr(String-Temporary)
leads to errors because it stores an expected-to-be invalid pointer.This PR prevents from using temporary
String
withStreamConstPtr
.(note :
StreamConstPtr("test").sendAll(elsewhere)
is implicitely using an intermediateString
)edit:
+ missing virtual destructor in
Stream::