[libcxx-commits] [PATCH] D157602: [libc++] Work around dynamic linking of stringstream::str() on Windows

Piotr Fusik via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 10 04:48:37 PDT 2023


pfusik created this revision.
Herald added a project: All.
pfusik requested review of this revision.
Herald added subscribers: libcxx-commits, bd1976llvm.
Herald added a project: libc++.
Herald added a reviewer: libc++.

Also `istringstream::str()` and `ostringstrem::str()`.

https://github.com/llvm/llvm-project/issues/40363 causes `str()`
to be dllimport'ed despite _LIBCPP_HIDE_FROM_ABI.
This is a temporary solution until #40363 is fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157602

Files:
  libcxx/include/sstream


Index: libcxx/include/sstream
===================================================================
--- libcxx/include/sstream
+++ libcxx/include/sstream
@@ -419,7 +419,7 @@
     }
 
     _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept;
-#endif
+#endif // _LIBCPP_STD_VER >= 20
 
     void str(const string_type& __s) {
         __str_ = __s;
@@ -904,20 +904,22 @@
         return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
     }
 
-#if _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); }
+#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
+    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
+#else
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); }
+
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); }
+#endif
 
+#if _LIBCPP_STD_VER >= 20
     template <class _SAlloc>
       requires __is_allocator<_SAlloc>::value
     _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
         return __sb_.str(__sa);
     }
 
-    _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
-
     _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
-#else // _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
@@ -1027,20 +1029,22 @@
         return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
     }
 
-#if _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); }
+#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
+    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
+#else
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); }
 
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); }
+#endif
+
+#if _LIBCPP_STD_VER >= 20
     template <class _SAlloc>
       requires __is_allocator<_SAlloc>::value
     _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
         return __sb_.str(__sa);
     }
 
-    _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
-
     _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
-#else // _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
@@ -1149,20 +1153,22 @@
         return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
     }
 
-#if _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); }
+#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
+    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
+#else
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); }
+
+    _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); }
+#endif
 
+#if _LIBCPP_STD_VER >= 20
     template <class _SAlloc>
       requires __is_allocator<_SAlloc>::value
     _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
         return __sb_.str(__sa);
     }
 
-    _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
-
     _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
-#else // _LIBCPP_STD_VER >= 20
-    _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157602.548975.patch
Type: text/x-patch
Size: 4097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230810/6706e8d0/attachment-0001.bin>


More information about the libcxx-commits mailing list