Index: include/string =================================================================== --- include/string +++ include/string @@ -22,7 +22,8 @@ private: stateT st; public: - fpos(streamoff = streamoff()); + fpos(); + fpos(streamoff); operator streamoff() const; @@ -30,13 +31,12 @@ void state(stateT); fpos& operator+=(streamoff); - fpos operator+ (streamoff) const; + fpos operator+ (fpos&) const; fpos& operator-=(streamoff); - fpos operator- (streamoff) const; + fpos operator- (fpos&) const; + fpos& operator= (fpos); }; -template streamoff operator-(const fpos& x, const fpos& y); - template bool operator==(const fpos& x, const fpos& y); template bool operator!=(const fpos& x, const fpos& y); @@ -540,29 +540,26 @@ _StateT __st_; streamoff __off_; public: - _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} + _LIBCPP_INLINE_VISIBILITY fpos() : __st_(), __off_(0 ) {} + _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off) : __st_(), __off_(__off) {} _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;} _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;} _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;} - _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;} - _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;} - _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;} - _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;} + _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) + {__off_ += __off; return *this;} + _LIBCPP_INLINE_VISIBILITY fpos operator+ (fpos<_StateT>& __rhs) const + {return fpos(__rhs.__off_ + __off_);} + _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) + {__off_ -= __off; return *this;} + _LIBCPP_INLINE_VISIBILITY fpos operator- (fpos<_StateT>& __rhs) const + {return fpos(__off_ - __rhs.__off_);} + _LIBCPP_INLINE_VISIBILITY fpos& operator= (fpos<_StateT> __rhs) + {_VSTD::swap(__rhs.__off_, __off_); return *this;} }; -template -inline _LIBCPP_INLINE_VISIBILITY -streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) - {return streamoff(__x) - streamoff(__y);} - -template -inline _LIBCPP_INLINE_VISIBILITY -bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) - {return streamoff(__x) == streamoff(__y);} - template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) @@ -627,13 +624,13 @@ #else template ::value> struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( - noexcept(++(declval<_Iter&>())) && - is_nothrow_assignable<_Iter&, _Iter>::value && - noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(++(declval<_Iter&>())) && + is_nothrow_assignable<_Iter&, _Iter>::value && + noexcept(declval<_Iter>() == declval<_Iter>()) && noexcept(*declval<_Iter>()) )) {}; -template +template struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; #endif @@ -1420,7 +1417,7 @@ _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; - + _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} @@ -1682,7 +1679,7 @@ -> basic_string<_CharT, _Traits, _Allocator>; #endif - + template inline void @@ -2525,7 +2522,7 @@ const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); } - else + else { if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); @@ -3824,7 +3821,7 @@ template inline -void +void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT { clear(); @@ -3834,7 +3831,7 @@ __set_long_cap(0); __set_short_size(0); } -} +} // operator== @@ -4331,7 +4328,7 @@ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals { Index: test/std/strings/fpos/fpos.pass.cpp =================================================================== --- /dev/null +++ test/std/strings/fpos/fpos.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "test_macros.h" + +#include +#include + +// string +// template +// class fpos +// { +// fpos(); +// fpos(streamoff); +// +// operator streamoff() const; +// +// fpos& operator+=(streamoff); +// fpos operator+ (fpos&) const; +// fpos& operator-=(streamoff); +// fpos operator- (fpos&) const; +// fpos& operator= (fpos); +// }; + +int main(int, char**) +{ + ASSERT_SAME_TYPE(std::streampos, std::fpos::state_type>); + + std::streampos p0; + assert(std::streamoff(p0) == 0); + + std::streampos p1(1); + assert(std::streamoff(p1) == 1); + + std::streampos p2 = 2; + assert(std::streamoff(p2) == 2); + + assert(p2 != p1); + + assert(std::streamoff(p1 + p2) == 3); + assert(std::streamoff(p2 - p1) == 1); + + p0 += 5; + assert(std::streamoff(p0) == 5); + p0 -= 2; + assert(std::streamoff(p0) == 3); + + assert((p0 + 3) == 6); + assert((p0 - 3) == 0); + + return 0; +}