Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WString: remove operator==(const __FlashStringHelper*) #8569

Merged
merged 8 commits into from
May 17, 2022
Merged
19 changes: 16 additions & 3 deletions cores/esp8266/WString.h
Original file line number Diff line number Diff line change
@@ -211,10 +211,9 @@ class String {
return *this;
}

// checks whether the internal buffer pointer is set.
// (should not be the case for us, since we always reset the pointer to the SSO buffer instead of setting it to nullptr)
// checks whether the String is empty
explicit operator bool() const {
return buffer() != nullptr;
return length() != 0;
}

int compareTo(const String &s) const;
@@ -230,6 +229,13 @@ class String {
bool operator ==(const __FlashStringHelper *rhs) const {
return equals(rhs);
}
bool operator ==(std::nullptr_t) const {
return length() == 0;
}
[[deprecated("use nullptr instead of NULL")]]
bool operator ==(decltype(NULL)) const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just note that the trade-off is someone will write obj == 5; returning false positive :)
(...and iirc ide default to 'no warnings', which does not help...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that std::nullptr_t is a distinguishable type, I tried the same with decltype(NULL).
Despite the existence of the __null internal keyword and the __sentinel__ attribute, I currently cannot manage NULL separately from int/long.

I reverted: ==(FlashStringHelper*) is removed again.

We still have this:
#define NULL nullptr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they refer to some old version of GCC (pre 4.6?) with the __null stuff.
And I'd like to find some examples of #define NULL std::nullptr, as it seems like something for the system header to have

Copy link
Collaborator Author

@d-a-v d-a-v May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only one I could find that is installed on my workstation and probably rarely used(*).

(*)given std:: and using are both lacking

Copy link
Collaborator

@mcspr mcspr May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return length() == 0;
}
bool operator !=(const String &rhs) const {
return !equals(rhs);
}
@@ -239,6 +245,13 @@ class String {
bool operator !=(const __FlashStringHelper *rhs) const {
return !equals(rhs);
}
bool operator !=(std::nullptr_t) const {
return length() != 0;
}
[[deprecated("use nullptr instead of NULL")]]
bool operator !=(decltype(NULL)) const {
return length() != 0;
}
bool operator <(const String &rhs) const;
bool operator >(const String &rhs) const;
bool operator <=(const String &rhs) const;