Skip to content

Commit 9a6cfb4

Browse files
committed
libcxx: see if clang-cl likes this.
Not for review.
1 parent 864f0ff commit 9a6cfb4

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

libcxx/include/__ostream/basic_ostream.h

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
7171

7272
public:
7373
// 27.7.2.4 Prefix/suffix:
74-
class sentry;
74+
class _LIBCPP_EXPORTED_FROM_ABI sentry;
7575

7676
// 27.7.2.6 Formatted output:
7777
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) {
@@ -181,42 +181,38 @@ class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
181181
};
182182

183183
template <class _CharT, class _Traits>
184-
class basic_ostream<_CharT, _Traits>::sentry {
184+
class _LIBCPP_EXPORTED_FROM_ABI basic_ostream<_CharT, _Traits>::sentry {
185185
bool __ok_;
186186
basic_ostream<_CharT, _Traits>& __os_;
187187

188188
public:
189-
explicit sentry(basic_ostream<_CharT, _Traits>& __os);
190-
~sentry();
191-
sentry(const sentry&) = delete;
192-
sentry& operator=(const sentry&) = delete;
193-
194-
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }
195-
};
196-
197-
template <class _CharT, class _Traits>
198-
basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) : __ok_(false), __os_(__os) {
199-
if (__os.good()) {
200-
if (__os.tie())
201-
__os.tie()->flush();
202-
__ok_ = true;
189+
explicit sentry(basic_ostream<_CharT, _Traits>& __os) : __ok_(false), __os_(__os) {
190+
if (__os.good()) {
191+
if (__os.tie())
192+
__os.tie()->flush();
193+
__ok_ = true;
194+
}
203195
}
204-
}
205196

206-
template <class _CharT, class _Traits>
207-
basic_ostream<_CharT, _Traits>::sentry::~sentry() {
208-
if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) {
197+
~sentry() {
198+
if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) {
209199
# if _LIBCPP_HAS_EXCEPTIONS
210-
try {
200+
try {
211201
# endif // _LIBCPP_HAS_EXCEPTIONS
212-
if (__os_.rdbuf()->pubsync() == -1)
213-
__os_.setstate(ios_base::badbit);
202+
if (__os_.rdbuf()->pubsync() == -1)
203+
__os_.setstate(ios_base::badbit);
214204
# if _LIBCPP_HAS_EXCEPTIONS
215-
} catch (...) {
216-
}
205+
} catch (...) {
206+
}
217207
# endif // _LIBCPP_HAS_EXCEPTIONS
208+
}
218209
}
219-
}
210+
211+
sentry(const sentry&) = delete;
212+
sentry& operator=(const sentry&) = delete;
213+
214+
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }
215+
};
220216

221217
template <class _CharT, class _Traits>
222218
basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) {

libcxx/include/istream

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public:
228228
basic_istream& operator=(const basic_istream& __rhs) = delete;
229229

230230
// 27.7.1.1.3 Prefix/suffix:
231-
class sentry;
231+
class _LIBCPP_EXPORTED_FROM_ABI sentry;
232232

233233
// 27.7.1.2 Formatted input:
234234
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) {
@@ -305,11 +305,29 @@ public:
305305
};
306306

307307
template <class _CharT, class _Traits>
308-
class basic_istream<_CharT, _Traits>::sentry {
308+
class _LIBCPP_EXPORTED_FROM_ABI basic_istream<_CharT, _Traits>::sentry {
309309
bool __ok_;
310310

311311
public:
312-
explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
312+
explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false) : __ok_(false) {
313+
if (__is.good()) {
314+
if (__is.tie())
315+
__is.tie()->flush();
316+
if (!__noskipws && (__is.flags() & ios_base::skipws)) {
317+
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
318+
const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
319+
_Ip __i(__is);
320+
_Ip __eof;
321+
for (; __i != __eof; ++__i)
322+
if (!__ct.is(__ct.space, *__i))
323+
break;
324+
if (__i == __eof)
325+
__is.setstate(ios_base::failbit | ios_base::eofbit);
326+
}
327+
__ok_ = __is.good();
328+
} else
329+
__is.setstate(ios_base::failbit);
330+
}
313331
// ~sentry() = default;
314332

315333
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }

0 commit comments

Comments
 (0)