Skip to content

Commit c24109f

Browse files
authored
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.
1 parent 4a24d3c commit c24109f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

cores/esp8266/WString.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ String::String(const __FlashStringHelper *pstr) {
4646
}
4747

4848
#ifdef __GXX_EXPERIMENTAL_CXX0X__
49-
String::String(String &&rval) {
49+
String::String(String &&rval) noexcept {
5050
init();
5151
move(rval);
5252
}
5353

54-
String::String(StringSumHelper &&rval) {
54+
String::String(StringSumHelper &&rval) noexcept {
5555
init();
5656
move(rval);
5757
}
@@ -224,7 +224,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
224224
}
225225

226226
#ifdef __GXX_EXPERIMENTAL_CXX0X__
227-
void String::move(String &rhs) {
227+
void String::move(String &rhs) noexcept {
228228
if (buffer()) {
229229
if (capacity() >= rhs.len()) {
230230
memmove_P(wbuffer(), rhs.buffer(), rhs.length() + 1);
@@ -267,13 +267,13 @@ String & String::operator =(const String &rhs) {
267267
}
268268

269269
#ifdef __GXX_EXPERIMENTAL_CXX0X__
270-
String & String::operator =(String &&rval) {
270+
String & String::operator =(String &&rval) noexcept {
271271
if (this != &rval)
272272
move(rval);
273273
return *this;
274274
}
275275

276-
String & String::operator =(StringSumHelper &&rval) {
276+
String & String::operator =(StringSumHelper &&rval) noexcept {
277277
if (this != &rval)
278278
move(rval);
279279
return *this;

cores/esp8266/WString.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class String {
5757
String(const String &str);
5858
String(const __FlashStringHelper *str);
5959
#ifdef __GXX_EXPERIMENTAL_CXX0X__
60-
String(String &&rval);
61-
String(StringSumHelper &&rval);
60+
String(String &&rval) noexcept;
61+
String(StringSumHelper &&rval) noexcept;
6262
#endif
6363
explicit String(char c);
6464
explicit String(unsigned char, unsigned char base = 10);
@@ -96,8 +96,8 @@ class String {
9696
String & operator =(const char *cstr);
9797
String & operator = (const __FlashStringHelper *str);
9898
#ifdef __GXX_EXPERIMENTAL_CXX0X__
99-
String & operator =(String &&rval);
100-
String & operator =(StringSumHelper &&rval);
99+
String & operator =(String &&rval) noexcept;
100+
String & operator =(StringSumHelper &&rval) noexcept;
101101
#endif
102102

103103
// concatenate (works w/ built-in types)
@@ -317,7 +317,7 @@ class String {
317317
String & copy(const char *cstr, unsigned int length);
318318
String & copy(const __FlashStringHelper *pstr, unsigned int length);
319319
#ifdef __GXX_EXPERIMENTAL_CXX0X__
320-
void move(String &rhs);
320+
void move(String &rhs) noexcept;
321321
#endif
322322
};
323323

0 commit comments

Comments
 (0)