From c24109fd57fc1a291805ed32629f7b073cc0d109 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Thu, 24 Sep 2020 05:35:32 +0300 Subject: [PATCH] WString: mark move ctor as noexcept (#7610) 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. --- cores/esp8266/WString.cpp | 10 +++++----- cores/esp8266/WString.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index 5498f8a23f..46aad5d5a0 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -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); } @@ -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); @@ -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; diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index fb2f0797f0..8e2db3f9b9 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -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); @@ -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) @@ -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 };