Commit f0fd118f by Jonathan Wakely Committed by Jonathan Wakely

re PR libstdc++/57394 ([C++11] basic_streambuf incorrect copy constructor / copy…

re PR libstdc++/57394 ([C++11] basic_streambuf incorrect copy constructor / copy assignment access specifier)

	PR libstdc++/57394
	* include/bits/ios_base.h (ios_base(const ios_base&)): Define as
	deleted for C++11.
	(operator=(const ios_base&)): Likewise.
	* include/std/streambuf: Remove trailing whitespace.
	(basic_streambuf(const basic_streambuf&)): Fix initializer for
	_M_out_end. Define as defaulted for C++11.
	(operator=(const basic_streambuf&)): Define as defaulted for C++11.
	(swap(basic_streambuf&)): Define for C++11.
	* testsuite/27_io/basic_streambuf/cons/57394.cc: New.

From-SVN: r210228
parent 8a8d1a16
2014-05-08 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/57394
* include/bits/ios_base.h (ios_base(const ios_base&)): Define as
deleted for C++11.
(operator=(const ios_base&)): Likewise.
* include/std/streambuf: Remove trailing whitespace.
(basic_streambuf(const basic_streambuf&)): Fix initializer for
_M_out_end. Define as defaulted for C++11.
(operator=(const basic_streambuf&)): Define as defaulted for C++11.
(swap(basic_streambuf&)): Define for C++11.
* testsuite/27_io/basic_streambuf/cons/57394.cc: New.
2014-05-08 Paolo Carlini <paolo.carlini@oracle.com> 2014-05-08 Paolo Carlini <paolo.carlini@oracle.com>
* acinclude.m4 ([GLIBCXX_ENABLE_C99]): Avoid -Wwrite-strings warning. * acinclude.m4 ([GLIBCXX_ENABLE_C99]): Avoid -Wwrite-strings warning.
......
...@@ -780,6 +780,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -780,6 +780,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
protected: protected:
ios_base() throw (); ios_base() throw ();
#if __cplusplus < 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 50. Copy constructor and assignment operator of ios_base // 50. Copy constructor and assignment operator of ios_base
private: private:
...@@ -787,6 +788,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -787,6 +788,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
ios_base& ios_base&
operator=(const ios_base&); operator=(const ios_base&);
#else
public:
ios_base(const ios_base&) = delete;
ios_base&
operator=(const ios_base&) = delete;
#endif
}; };
// [27.4.5.1] fmtflags manipulators // [27.4.5.1] fmtflags manipulators
......
...@@ -117,7 +117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -117,7 +117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* from the sequence). * from the sequence).
*/ */
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
class basic_streambuf class basic_streambuf
{ {
public: public:
//@{ //@{
...@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// This is a non-standard type. /// This is a non-standard type.
typedef basic_streambuf<char_type, traits_type> __streambuf_type; typedef basic_streambuf<char_type, traits_type> __streambuf_type;
//@} //@}
friend class basic_ios<char_type, traits_type>; friend class basic_ios<char_type, traits_type>;
friend class basic_istream<char_type, traits_type>; friend class basic_istream<char_type, traits_type>;
friend class basic_ostream<char_type, traits_type>; friend class basic_ostream<char_type, traits_type>;
...@@ -148,7 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -148,7 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&); __copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&);
template<bool _IsMove, typename _CharT2> template<bool _IsMove, typename _CharT2>
friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
_CharT2*>::__type _CharT2*>::__type
__copy_move_a2(istreambuf_iterator<_CharT2>, __copy_move_a2(istreambuf_iterator<_CharT2>,
istreambuf_iterator<_CharT2>, _CharT2*); istreambuf_iterator<_CharT2>, _CharT2*);
...@@ -189,12 +189,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -189,12 +189,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
char_type* _M_out_end; ///< End of put area. char_type* _M_out_end; ///< End of put area.
/// Current locale setting. /// Current locale setting.
locale _M_buf_locale; locale _M_buf_locale;
public: public:
/// Destructor deallocates no buffer space. /// Destructor deallocates no buffer space.
virtual virtual
~basic_streambuf() ~basic_streambuf()
{ } { }
// [27.5.2.2.1] locales // [27.5.2.2.1] locales
...@@ -205,7 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -205,7 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* Calls the derived imbue(__loc). * Calls the derived imbue(__loc).
*/ */
locale locale
pubimbue(const locale& __loc) pubimbue(const locale& __loc)
{ {
locale __tmp(this->getloc()); locale __tmp(this->getloc());
...@@ -222,9 +222,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -222,9 +222,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* is returned. Otherwise the global locale in effect at the time * is returned. Otherwise the global locale in effect at the time
* of construction is returned. * of construction is returned.
*/ */
locale locale
getloc() const getloc() const
{ return _M_buf_locale; } { return _M_buf_locale; }
// [27.5.2.2.2] buffer management and positioning // [27.5.2.2.2] buffer management and positioning
//@{ //@{
...@@ -236,7 +236,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -236,7 +236,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* and returning the result unchanged. * and returning the result unchanged.
*/ */
basic_streambuf* basic_streambuf*
pubsetbuf(char_type* __s, streamsize __n) pubsetbuf(char_type* __s, streamsize __n)
{ return this->setbuf(__s, __n); } { return this->setbuf(__s, __n); }
/** /**
...@@ -247,8 +247,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -247,8 +247,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* Calls virtual seekoff function. * Calls virtual seekoff function.
*/ */
pos_type pos_type
pubseekoff(off_type __off, ios_base::seekdir __way, pubseekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __mode = ios_base::in | ios_base::out) ios_base::openmode __mode = ios_base::in | ios_base::out)
{ return this->seekoff(__off, __way, __mode); } { return this->seekoff(__off, __way, __mode); }
...@@ -259,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -259,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* Calls virtual seekpos function. * Calls virtual seekpos function.
*/ */
pos_type pos_type
pubseekpos(pos_type __sp, pubseekpos(pos_type __sp,
ios_base::openmode __mode = ios_base::in | ios_base::out) ios_base::openmode __mode = ios_base::in | ios_base::out)
{ return this->seekpos(__sp, __mode); } { return this->seekpos(__sp, __mode); }
...@@ -267,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -267,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/** /**
* @brief Calls virtual sync function. * @brief Calls virtual sync function.
*/ */
int int
pubsync() { return this->sync(); } pubsync() { return this->sync(); }
//@} //@}
...@@ -280,9 +280,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -280,9 +280,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* available for reading before the buffer must be refilled. * available for reading before the buffer must be refilled.
* Otherwise returns the derived @c showmanyc(). * Otherwise returns the derived @c showmanyc().
*/ */
streamsize streamsize
in_avail() in_avail()
{ {
const streamsize __ret = this->egptr() - this->gptr(); const streamsize __ret = this->egptr() - this->gptr();
return __ret ? __ret : this->showmanyc(); return __ret ? __ret : this->showmanyc();
} }
...@@ -294,11 +294,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -294,11 +294,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Calls @c sbumpc(), and if that function returns * Calls @c sbumpc(), and if that function returns
* @c traits::eof(), so does this function. Otherwise, @c sgetc(). * @c traits::eof(), so does this function. Otherwise, @c sgetc().
*/ */
int_type int_type
snextc() snextc()
{ {
int_type __ret = traits_type::eof(); int_type __ret = traits_type::eof();
if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(), if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
__ret), true)) __ret), true))
__ret = this->sgetc(); __ret = this->sgetc();
return __ret; return __ret;
...@@ -312,7 +312,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -312,7 +312,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* and increments the read pointer, otherwise calls and returns * and increments the read pointer, otherwise calls and returns
* @c uflow(). * @c uflow().
*/ */
int_type int_type
sbumpc() sbumpc()
{ {
int_type __ret; int_type __ret;
...@@ -321,7 +321,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -321,7 +321,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__ret = traits_type::to_int_type(*this->gptr()); __ret = traits_type::to_int_type(*this->gptr());
this->gbump(1); this->gbump(1);
} }
else else
__ret = this->uflow(); __ret = this->uflow();
return __ret; return __ret;
} }
...@@ -331,16 +331,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -331,16 +331,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @return The next character, or eof. * @return The next character, or eof.
* *
* If the input read position is available, returns that character, * If the input read position is available, returns that character,
* otherwise calls and returns @c underflow(). Does not move the * otherwise calls and returns @c underflow(). Does not move the
* read position after fetching the character. * read position after fetching the character.
*/ */
int_type int_type
sgetc() sgetc()
{ {
int_type __ret; int_type __ret;
if (__builtin_expect(this->gptr() < this->egptr(), true)) if (__builtin_expect(this->gptr() < this->egptr(), true))
__ret = traits_type::to_int_type(*this->gptr()); __ret = traits_type::to_int_type(*this->gptr());
else else
__ret = this->underflow(); __ret = this->underflow();
return __ret; return __ret;
} }
...@@ -353,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -353,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through * Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through
* @a __s[__n-1] with characters from the input sequence, if possible. * @a __s[__n-1] with characters from the input sequence, if possible.
*/ */
streamsize streamsize
sgetn(char_type* __s, streamsize __n) sgetn(char_type* __s, streamsize __n)
{ return this->xsgetn(__s, __n); } { return this->xsgetn(__s, __n); }
...@@ -368,15 +368,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -368,15 +368,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* the next character fetched from the input stream will be @a * the next character fetched from the input stream will be @a
* __c. * __c.
*/ */
int_type int_type
sputbackc(char_type __c) sputbackc(char_type __c)
{ {
int_type __ret; int_type __ret;
const bool __testpos = this->eback() < this->gptr(); const bool __testpos = this->eback() < this->gptr();
if (__builtin_expect(!__testpos || if (__builtin_expect(!__testpos ||
!traits_type::eq(__c, this->gptr()[-1]), false)) !traits_type::eq(__c, this->gptr()[-1]), false))
__ret = this->pbackfail(traits_type::to_int_type(__c)); __ret = this->pbackfail(traits_type::to_int_type(__c));
else else
{ {
this->gbump(-1); this->gbump(-1);
__ret = traits_type::to_int_type(*this->gptr()); __ret = traits_type::to_int_type(*this->gptr());
...@@ -393,7 +393,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -393,7 +393,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* calls and returns pbackfail(). The effect is to @a unget * calls and returns pbackfail(). The effect is to @a unget
* the last character @a gotten. * the last character @a gotten.
*/ */
int_type int_type
sungetc() sungetc()
{ {
int_type __ret; int_type __ret;
...@@ -402,7 +402,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -402,7 +402,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
this->gbump(-1); this->gbump(-1);
__ret = traits_type::to_int_type(*this->gptr()); __ret = traits_type::to_int_type(*this->gptr());
} }
else else
__ret = this->pbackfail(); __ret = this->pbackfail();
return __ret; return __ret;
} }
...@@ -420,7 +420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -420,7 +420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* the position, and returns @c traits::to_int_type(__c). If a write * the position, and returns @c traits::to_int_type(__c). If a write
* position is not available, returns @c overflow(__c). * position is not available, returns @c overflow(__c).
*/ */
int_type int_type
sputc(char_type __c) sputc(char_type __c)
{ {
int_type __ret; int_type __ret;
...@@ -446,7 +446,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -446,7 +446,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Returns xsputn(__s,__n). The effect is to write @a __s[0] through * Returns xsputn(__s,__n). The effect is to write @a __s[0] through
* @a __s[__n-1] to the output sequence, if possible. * @a __s[__n-1] to the output sequence, if possible.
*/ */
streamsize streamsize
sputn(const char_type* __s, streamsize __n) sputn(const char_type* __s, streamsize __n)
{ return this->xsputn(__s, __n); } { return this->xsputn(__s, __n); }
...@@ -461,9 +461,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -461,9 +461,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* - this is not an error * - this is not an error
*/ */
basic_streambuf() basic_streambuf()
: _M_in_beg(0), _M_in_cur(0), _M_in_end(0), : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
_M_out_beg(0), _M_out_cur(0), _M_out_end(0), _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
_M_buf_locale(locale()) _M_buf_locale(locale())
{ } { }
// [27.5.2.3.1] get area access // [27.5.2.3.1] get area access
...@@ -478,13 +478,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -478,13 +478,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* - gptr() returns the next pointer for the input sequence * - gptr() returns the next pointer for the input sequence
* - egptr() returns the end pointer for the input sequence * - egptr() returns the end pointer for the input sequence
*/ */
char_type* char_type*
eback() const { return _M_in_beg; } eback() const { return _M_in_beg; }
char_type* char_type*
gptr() const { return _M_in_cur; } gptr() const { return _M_in_cur; }
char_type* char_type*
egptr() const { return _M_in_end; } egptr() const { return _M_in_end; }
//@} //@}
...@@ -494,7 +494,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -494,7 +494,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* This just advances the read position without returning any data. * This just advances the read position without returning any data.
*/ */
void void
gbump(int __n) { _M_in_cur += __n; } gbump(int __n) { _M_in_cur += __n; }
/** /**
...@@ -505,7 +505,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -505,7 +505,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and * @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and
* @a __gend == @c egptr() * @a __gend == @c egptr()
*/ */
void void
setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
{ {
_M_in_beg = __gbeg; _M_in_beg = __gbeg;
...@@ -525,13 +525,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -525,13 +525,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* - pptr() returns the next pointer for the output sequence * - pptr() returns the next pointer for the output sequence
* - epptr() returns the end pointer for the output sequence * - epptr() returns the end pointer for the output sequence
*/ */
char_type* char_type*
pbase() const { return _M_out_beg; } pbase() const { return _M_out_beg; }
char_type* char_type*
pptr() const { return _M_out_cur; } pptr() const { return _M_out_cur; }
char_type* char_type*
epptr() const { return _M_out_end; } epptr() const { return _M_out_end; }
//@} //@}
...@@ -541,7 +541,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -541,7 +541,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* This just advances the write position without returning any data. * This just advances the write position without returning any data.
*/ */
void void
pbump(int __n) { _M_out_cur += __n; } pbump(int __n) { _M_out_cur += __n; }
/** /**
...@@ -551,10 +551,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -551,10 +551,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and * @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and
* @a __pend == @c epptr() * @a __pend == @c epptr()
*/ */
void void
setp(char_type* __pbeg, char_type* __pend) setp(char_type* __pbeg, char_type* __pend)
{ {
_M_out_beg = _M_out_cur = __pbeg; _M_out_beg = _M_out_cur = __pbeg;
_M_out_end = __pend; _M_out_end = __pend;
} }
...@@ -572,8 +572,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -572,8 +572,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* @note Base class version does nothing. * @note Base class version does nothing.
*/ */
virtual void virtual void
imbue(const locale& __loc) imbue(const locale& __loc)
{ } { }
// [27.5.2.4.2] buffer management and positioning // [27.5.2.4.2] buffer management and positioning
...@@ -581,16 +581,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -581,16 +581,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Manipulates the buffer. * @brief Manipulates the buffer.
* *
* Each derived class provides its own appropriate behavior. See * Each derived class provides its own appropriate behavior. See
* the next-to-last paragraph of * the next-to-last paragraph of
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html
* for more on this function. * for more on this function.
* *
* @note Base class version does nothing, returns @c this. * @note Base class version does nothing, returns @c this.
*/ */
virtual basic_streambuf<char_type,_Traits>* virtual basic_streambuf<char_type,_Traits>*
setbuf(char_type*, streamsize) setbuf(char_type*, streamsize)
{ return this; } { return this; }
/** /**
* @brief Alters the stream positions. * @brief Alters the stream positions.
* *
...@@ -598,10 +598,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -598,10 +598,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @note Base class version does nothing, returns a @c pos_type * @note Base class version does nothing, returns a @c pos_type
* that represents an invalid stream position. * that represents an invalid stream position.
*/ */
virtual pos_type virtual pos_type
seekoff(off_type, ios_base::seekdir, seekoff(off_type, ios_base::seekdir,
ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
{ return pos_type(off_type(-1)); } { return pos_type(off_type(-1)); }
/** /**
* @brief Alters the stream positions. * @brief Alters the stream positions.
...@@ -610,10 +610,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -610,10 +610,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @note Base class version does nothing, returns a @c pos_type * @note Base class version does nothing, returns a @c pos_type
* that represents an invalid stream position. * that represents an invalid stream position.
*/ */
virtual pos_type virtual pos_type
seekpos(pos_type, seekpos(pos_type,
ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
{ return pos_type(off_type(-1)); } { return pos_type(off_type(-1)); }
/** /**
* @brief Synchronizes the buffer arrays with the controlled sequences. * @brief Synchronizes the buffer arrays with the controlled sequences.
...@@ -623,7 +623,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -623,7 +623,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* including the definition of @a failure. * including the definition of @a failure.
* @note Base class version does nothing, returns zero. * @note Base class version does nothing, returns zero.
*/ */
virtual int virtual int
sync() { return 0; } sync() { return 0; }
// [27.5.2.4.3] get area // [27.5.2.4.3] get area
...@@ -645,7 +645,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -645,7 +645,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @note The standard adds that <em>the morphemes of @c showmanyc are * @note The standard adds that <em>the morphemes of @c showmanyc are
* @b es-how-many-see, not @b show-manic.</em> * @b es-how-many-see, not @b show-manic.</em>
*/ */
virtual streamsize virtual streamsize
showmanyc() { return 0; } showmanyc() { return 0; }
/** /**
...@@ -661,7 +661,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -661,7 +661,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* It is expected that derived classes provide a more efficient * It is expected that derived classes provide a more efficient
* implementation by overriding this definition. * implementation by overriding this definition.
*/ */
virtual streamsize virtual streamsize
xsgetn(char_type* __s, streamsize __n); xsgetn(char_type* __s, streamsize __n);
/** /**
...@@ -683,7 +683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -683,7 +683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* @note Base class version does nothing, returns eof(). * @note Base class version does nothing, returns eof().
*/ */
virtual int_type virtual int_type
underflow() underflow()
{ return traits_type::eof(); } { return traits_type::eof(); }
...@@ -696,18 +696,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -696,18 +696,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* the new character, like @c underflow() does. However, this * the new character, like @c underflow() does. However, this
* function also moves the read position forward by one. * function also moves the read position forward by one.
*/ */
virtual int_type virtual int_type
uflow() uflow()
{ {
int_type __ret = traits_type::eof(); int_type __ret = traits_type::eof();
const bool __testeof = traits_type::eq_int_type(this->underflow(), const bool __testeof = traits_type::eq_int_type(this->underflow(),
__ret); __ret);
if (!__testeof) if (!__testeof)
{ {
__ret = traits_type::to_int_type(*this->gptr()); __ret = traits_type::to_int_type(*this->gptr());
this->gbump(1); this->gbump(1);
} }
return __ret; return __ret;
} }
// [27.5.2.4.4] putback // [27.5.2.4.4] putback
...@@ -720,7 +720,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -720,7 +720,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* @note Base class version does nothing, returns eof(). * @note Base class version does nothing, returns eof().
*/ */
virtual int_type virtual int_type
pbackfail(int_type __c = traits_type::eof()) pbackfail(int_type __c = traits_type::eof())
{ return traits_type::eof(); } { return traits_type::eof(); }
...@@ -738,7 +738,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -738,7 +738,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* It is expected that derived classes provide a more efficient * It is expected that derived classes provide a more efficient
* implementation by overriding this definition. * implementation by overriding this definition.
*/ */
virtual streamsize virtual streamsize
xsputn(const char_type* __s, streamsize __n); xsputn(const char_type* __s, streamsize __n);
/** /**
...@@ -764,7 +764,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -764,7 +764,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* @note Base class version does nothing, returns eof(). * @note Base class version does nothing, returns eof().
*/ */
virtual int_type virtual int_type
overflow(int_type __c = traits_type::eof()) overflow(int_type __c = traits_type::eof())
{ return traits_type::eof(); } { return traits_type::eof(); }
...@@ -779,35 +779,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -779,35 +779,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* *
* See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
*/ */
void void
stossc() stossc()
{ {
if (this->gptr() < this->egptr()) if (this->gptr() < this->egptr())
this->gbump(1); this->gbump(1);
else else
this->uflow(); this->uflow();
} }
#endif #endif
// Also used by specializations for char and wchar_t in src. // Also used by specializations for char and wchar_t in src.
void void
__safe_gbump(streamsize __n) { _M_in_cur += __n; } __safe_gbump(streamsize __n) { _M_in_cur += __n; }
void void
__safe_pbump(streamsize __n) { _M_out_cur += __n; } __safe_pbump(streamsize __n) { _M_out_cur += __n; }
#if __cplusplus < 201103L
private: private:
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// Side effect of DR 50. // Side effect of DR 50.
basic_streambuf(const basic_streambuf& __sb) basic_streambuf(const basic_streambuf& __sb)
: _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur), : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
_M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg), _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg),
_M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur), _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_end),
_M_buf_locale(__sb._M_buf_locale) _M_buf_locale(__sb._M_buf_locale)
{ } { }
basic_streambuf& basic_streambuf&
operator=(const basic_streambuf&) { return *this; }; operator=(const basic_streambuf&) { return *this; }
#else
protected:
basic_streambuf(const basic_streambuf&) = default;
basic_streambuf&
operator=(const basic_streambuf&) = default;
void
swap(basic_streambuf& __sb)
{
std::swap(_M_in_beg, __sb._M_in_beg);
std::swap(_M_in_cur, __sb._M_in_cur);
std::swap(_M_in_end, __sb._M_in_end);
std::swap(_M_out_beg, __sb._M_out_beg);
std::swap(_M_out_cur, __sb._M_out_cur);
std::swap(_M_out_end, __sb._M_out_end);
std::swap(_M_buf_locale, __sb._M_buf_locale);
}
#endif
}; };
// Explicit specialization declarations, defined in src/streambuf.cc. // Explicit specialization declarations, defined in src/streambuf.cc.
......
// Copyright (C) 2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++11" }
// { dg-require-namedlocale "de_DE" }
// 27.6.3 template class basic_streambuf
#include <streambuf>
#include <testsuite_hooks.h>
struct streambuf : std::streambuf
{
streambuf()
{
setp(pbuf, std::end(pbuf));
setg(gbuf, gbuf, gbuf);
}
streambuf(const std::locale& loc) : streambuf()
{
imbue(loc);
}
// implement tests as member functions to be able to call protected members
void test_copy() const;
void test_assign() const;
void test_swap() const;
char gbuf[32];
char pbuf[32];
};
void streambuf::test_copy() const
{
bool test __attribute__((unused)) = true;
streambuf a(*this);
VERIFY( eback() == a.eback() );
VERIFY( gptr() == a.gptr() );
VERIFY( egptr() == a.egptr() );
VERIFY( pbase() == a.pbase() );
VERIFY( pptr() == a.pptr() );
VERIFY( epptr() == a.epptr() );
VERIFY( getloc() == a.getloc() );
}
void streambuf::test_assign() const
{
bool test __attribute__((unused)) = true;
streambuf a;
a = *this;
VERIFY( eback() == a.eback() );
VERIFY( gptr() == a.gptr() );
VERIFY( egptr() == a.egptr() );
VERIFY( pbase() == a.pbase() );
VERIFY( pptr() == a.pptr() );
VERIFY( epptr() == a.epptr() );
VERIFY( getloc() == a.getloc() );
}
void streambuf::test_swap() const
{
bool test __attribute__((unused)) = true;
streambuf a(*this);
streambuf b;
const streambuf c(b);
a.swap(b);
VERIFY( eback() == b.eback() );
VERIFY( gptr() == b.gptr() );
VERIFY( egptr() == b.egptr() );
VERIFY( pbase() == b.pbase() );
VERIFY( pptr() == b.pptr() );
VERIFY( epptr() == b.epptr() );
VERIFY( getloc() == b.getloc() );
VERIFY( c.eback() == a.eback() );
VERIFY( c.gptr() == a.gptr() );
VERIFY( c.egptr() == a.egptr() );
VERIFY( c.pbase() == a.pbase() );
VERIFY( c.pptr() == a.pptr() );
VERIFY( c.epptr() == a.epptr() );
VERIFY( c.getloc() == a.getloc() );
}
int main()
{
std::locale loc("de_DE");
streambuf s(loc);
s.test_copy();
s.test_assign();
s.test_swap();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment