summaryrefslogtreecommitdiff
path: root/libcxx/include/syncstream
diff options
context:
space:
mode:
authorLouis Dionne <ldionne.2@gmail.com>2024-09-16 08:15:38 -0400
committerGitHub <noreply@github.com>2024-09-16 08:15:38 -0400
commit87d56c59f52d033cd7c46d769338b9c47fea4929 (patch)
treead6dae3bd0ad7862d6092ca1dcc6b95d29162b7d /libcxx/include/syncstream
parent1881f648e28aa58aa0a4dca1422572f65dafa9a4 (diff)
[libc++][modules] Guard carved-out headers more consistently (#108637)
Several headers that should not be provided when localization or threads are disabled were not guarded. That works until one tries to build with modules and these headers get pulled in. Note that this could be cleaned up further into something more systematic, but this patch solves the immediate problems I ran into with the monolithic modulemap and doesn't create any new inconsistency that wasn't already there.
Diffstat (limited to 'libcxx/include/syncstream')
-rw-r--r--libcxx/include/syncstream89
1 files changed, 47 insertions, 42 deletions
diff --git a/libcxx/include/syncstream b/libcxx/include/syncstream
index fea4c66b8e11..fe9aa07fcdaa 100644
--- a/libcxx/include/syncstream
+++ b/libcxx/include/syncstream
@@ -118,33 +118,36 @@ namespace std {
*/
#include <__config>
-#include <__utility/move.h>
-#include <ios>
-#include <iosfwd> // required for declaration of default arguments
-#include <streambuf>
-#include <string>
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-# include <map>
-# include <mutex>
-# include <shared_mutex>
-#endif
+
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+
+# include <__utility/move.h>
+# include <ios>
+# include <iosfwd> // required for declaration of default arguments
+# include <streambuf>
+# include <string>
+
+# ifndef _LIBCPP_HAS_NO_THREADS
+# include <map>
+# include <mutex>
+# include <shared_mutex>
+# endif
// standard-mandated includes
// [syncstream.syn]
-#include <ostream>
+# include <ostream>
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-#endif
+# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+# endif
_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
+# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
-#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
+# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
// [syncstream.syncbuf.overview]/1
// Class template basic_syncbuf stores character data written to it,
@@ -157,7 +160,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
//
// This helper singleton is used to implement the required
// synchronisation guarantees.
-# ifndef _LIBCPP_HAS_NO_THREADS
+# ifndef _LIBCPP_HAS_NO_THREADS
class __wrapped_streambuf_mutex {
_LIBCPP_HIDE_FROM_ABI __wrapped_streambuf_mutex() = default;
@@ -230,7 +233,7 @@ private:
return __it;
}
};
-# endif // _LIBCPP_HAS_NO_THREADS
+# endif // _LIBCPP_HAS_NO_THREADS
// basic_syncbuf
@@ -270,14 +273,14 @@ public:
}
_LIBCPP_HIDE_FROM_ABI ~basic_syncbuf() {
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
try {
-# endif // _LIBCPP_HAS_NO_EXCEPTIONS
+# endif // _LIBCPP_HAS_NO_EXCEPTIONS
emit();
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
}
-# endif // _LIBCPP_HAS_NO_EXCEPTIONS
+# endif // _LIBCPP_HAS_NO_EXCEPTIONS
__dec_reference();
}
@@ -334,9 +337,9 @@ protected:
return traits_type::not_eof(__c);
if (this->pptr() == this->epptr()) {
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
try {
-# endif
+# endif
size_t __size = __str_.size();
__str_.resize(__str_.capacity() + 1);
_LIBCPP_ASSERT_INTERNAL(__str_.size() > __size, "the buffer hasn't grown");
@@ -345,11 +348,11 @@ protected:
this->setp(__p, __p + __str_.size());
this->pbump(__size);
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
return traits_type::eof();
}
-# endif
+# endif
}
return this->sputc(traits_type::to_char_type(__c));
@@ -370,9 +373,9 @@ private:
if (!__wrapped_)
return false;
-# ifndef _LIBCPP_HAS_NO_THREADS
+# ifndef _LIBCPP_HAS_NO_THREADS
lock_guard<mutex> __lock = __wrapped_streambuf_mutex::__instance().__get_lock(__wrapped_);
-# endif
+# endif
bool __result = true;
if (this->pptr() != this->pbase()) {
@@ -404,24 +407,24 @@ private:
}
_LIBCPP_HIDE_FROM_ABI void __inc_reference() {
-# ifndef _LIBCPP_HAS_NO_THREADS
+# ifndef _LIBCPP_HAS_NO_THREADS
if (__wrapped_)
__wrapped_streambuf_mutex::__instance().__inc_reference(__wrapped_);
-# endif
+# endif
}
_LIBCPP_HIDE_FROM_ABI void __dec_reference() noexcept {
-# ifndef _LIBCPP_HAS_NO_THREADS
+# ifndef _LIBCPP_HAS_NO_THREADS
if (__wrapped_)
__wrapped_streambuf_mutex::__instance().__dec_reference(__wrapped_);
-# endif
+# endif
}
};
using std::syncbuf;
-# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wsyncbuf;
-# endif
+# endif
// [syncstream.syncbuf.special], specialized algorithms
template <class _CharT, class _Traits, class _Allocator>
@@ -477,17 +480,17 @@ public:
// TODO validate other unformatted output functions.
typename basic_ostream<char_type, traits_type>::sentry __s(*this);
if (__s) {
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
try {
-# endif
+# endif
if (__sb_.emit() == false)
this->setstate(ios::badbit);
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
} catch (...) {
this->__set_badbit_and_consider_rethrow();
}
-# endif
+# endif
}
}
@@ -502,14 +505,16 @@ private:
};
using std::osyncstream;
-# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
using std::wosyncstream;
-# endif
+# endif
-#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
+# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
+#endif // !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+
#endif // _LIBCPP_SYNCSTREAM