Skip to content

Commit

Permalink
WString: mark move ctor as noexcept (#7610)
Browse files Browse the repository at this point in the history
ref.
- https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-move-noexcept
- https://rules.sonarsource.com/cpp/RSPEC-5018?search=noexecept
- https://clang.llvm.org/extra/clang-tidy/checks/performance-noexcept-move-constructor.html

> Move constructors of all the types used with STL containers, for
example, need to be declared noexcept. Otherwise STL will choose copy
constructors instead. The same is valid for move assignment operations.
  • Loading branch information
mcspr committed Sep 24, 2020
1 parent 4a24d3c commit c24109f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ String::String(const __FlashStringHelper *pstr) {
}

#ifdef __GXX_EXPERIMENTAL_CXX0X__
String::String(String &&rval) {
String::String(String &&rval) noexcept {
init();
move(rval);
}

String::String(StringSumHelper &&rval) {
String::String(StringSumHelper &&rval) noexcept {
init();
move(rval);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
}

#ifdef __GXX_EXPERIMENTAL_CXX0X__
void String::move(String &rhs) {
void String::move(String &rhs) noexcept {
if (buffer()) {
if (capacity() >= rhs.len()) {
memmove_P(wbuffer(), rhs.buffer(), rhs.length() + 1);
Expand Down Expand Up @@ -267,13 +267,13 @@ String & String::operator =(const String &rhs) {
}

#ifdef __GXX_EXPERIMENTAL_CXX0X__
String & String::operator =(String &&rval) {
String & String::operator =(String &&rval) noexcept {
if (this != &rval)
move(rval);
return *this;
}

String & String::operator =(StringSumHelper &&rval) {
String & String::operator =(StringSumHelper &&rval) noexcept {
if (this != &rval)
move(rval);
return *this;
Expand Down
10 changes: 5 additions & 5 deletions cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class String {
String(const String &str);
String(const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(String &&rval);
String(StringSumHelper &&rval);
String(String &&rval) noexcept;
String(StringSumHelper &&rval) noexcept;
#endif
explicit String(char c);
explicit String(unsigned char, unsigned char base = 10);
Expand Down Expand Up @@ -96,8 +96,8 @@ class String {
String & operator =(const char *cstr);
String & operator = (const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String & operator =(String &&rval);
String & operator =(StringSumHelper &&rval);
String & operator =(String &&rval) noexcept;
String & operator =(StringSumHelper &&rval) noexcept;
#endif

// concatenate (works w/ built-in types)
Expand Down Expand Up @@ -317,7 +317,7 @@ class String {
String & copy(const char *cstr, unsigned int length);
String & copy(const __FlashStringHelper *pstr, unsigned int length);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void move(String &rhs);
void move(String &rhs) noexcept;
#endif
};

Expand Down

0 comments on commit c24109f

Please sign in to comment.