Fix a bug in the move-assigment operator for basic_stringbuf. Thanks to Johnathan Wakeley for the bug report
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@217894 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
86d311c5f3
commit
4413ab09d5
@ -325,11 +325,16 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
|
|||||||
__p = const_cast<char_type*>(__str_.data());
|
__p = const_cast<char_type*>(__str_.data());
|
||||||
if (__binp != -1)
|
if (__binp != -1)
|
||||||
this->setg(__p + __binp, __p + __ninp, __p + __einp);
|
this->setg(__p + __binp, __p + __ninp, __p + __einp);
|
||||||
|
else
|
||||||
|
this->setg(nullptr, nullptr, nullptr);
|
||||||
if (__bout != -1)
|
if (__bout != -1)
|
||||||
{
|
{
|
||||||
this->setp(__p + __bout, __p + __eout);
|
this->setp(__p + __bout, __p + __eout);
|
||||||
this->pbump(__nout);
|
this->pbump(__nout);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
this->setp(nullptr, nullptr);
|
||||||
|
|
||||||
__hm_ = __hm == -1 ? nullptr : __p + __hm;
|
__hm_ = __hm == -1 ? nullptr : __p + __hm;
|
||||||
__mode_ = __rhs.__mode_;
|
__mode_ = __rhs.__mode_;
|
||||||
__p = const_cast<char_type*>(__rhs.__str_.data());
|
__p = const_cast<char_type*>(__rhs.__str_.data());
|
||||||
|
@ -33,6 +33,24 @@ int main()
|
|||||||
ss >> i;
|
ss >> i;
|
||||||
assert(i == 456);
|
assert(i == 456);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
std::istringstream s1("Aaaaa Bbbbb Cccccccccc Dddddddddddddddddd");
|
||||||
|
std::string s;
|
||||||
|
s1 >> s;
|
||||||
|
|
||||||
|
std::istringstream s2 = std::move(s1);
|
||||||
|
s2 >> s;
|
||||||
|
assert(s == "Bbbbb");
|
||||||
|
|
||||||
|
std::istringstream s3;
|
||||||
|
s3 = std::move(s2);
|
||||||
|
s3 >> s;
|
||||||
|
assert(s == "Cccccccccc");
|
||||||
|
|
||||||
|
s1 = std::move(s3);
|
||||||
|
s1 >> s;
|
||||||
|
assert(s == "Dddddddddddddddddd");
|
||||||
|
}
|
||||||
{
|
{
|
||||||
std::wistringstream ss0(L" 123 456");
|
std::wistringstream ss0(L" 123 456");
|
||||||
std::wistringstream ss;
|
std::wistringstream ss;
|
||||||
@ -46,5 +64,23 @@ int main()
|
|||||||
ss >> i;
|
ss >> i;
|
||||||
assert(i == 456);
|
assert(i == 456);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
std::wistringstream s1(L"Aaaaa Bbbbb Cccccccccc Dddddddddddddddddd");
|
||||||
|
std::wstring s;
|
||||||
|
s1 >> s;
|
||||||
|
|
||||||
|
std::wistringstream s2 = std::move(s1);
|
||||||
|
s2 >> s;
|
||||||
|
assert(s == L"Bbbbb");
|
||||||
|
|
||||||
|
std::wistringstream s3;
|
||||||
|
s3 = std::move(s2);
|
||||||
|
s3 >> s;
|
||||||
|
assert(s == L"Cccccccccc");
|
||||||
|
|
||||||
|
s1 = std::move(s3);
|
||||||
|
s1 >> s;
|
||||||
|
assert(s == L"Dddddddddddddddddd");
|
||||||
|
}
|
||||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user