]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Define std::basic_stringbuf::view() for old std::string ABI
authorJonathan Wakely <jwakely@redhat.com>
Tue, 31 Jan 2023 22:32:15 +0000 (22:32 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 18 Mar 2024 13:50:54 +0000 (13:50 +0000)
Unlike the new str()&& members in <sstream>, there is no real difficulty
in supporting the new view() members for the old std::string ABI.
Enabling it fixes errors in <chrono> where std::ostringstream::view() is
used by ostream insertion operators for calendar types.

We just need to use [[gnu::always_inline]] on the view() members for the
old ABI, because the library doesn't contain instantiations of them for
the old ABI. Making them always inline avoids needing to add those
instantiations and export them.

libstdc++-v3/ChangeLog:

* include/std/sstream  (basic_stringbuf::view): Define for old
std::string ABI.
(basic_istringstream::view, basic_stringstream::view)
(basic_stringstream::view): Likewise.
* testsuite/27_io/basic_istringstream/view/char/1.cc: Remove
{ dg-require-effective-target cxx11_abi }.
* testsuite/27_io/basic_istringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_ostringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc:
Likewise.

(cherry picked from commit 331b4f168a06cd85fe40fd03b48b128cc8af399c)

libstdc++-v3/include/std/sstream
libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc
libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc
libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc
libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc
libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc
libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc
libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc
libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc

index bc7d636e702ea4352a182cc521fd32a06ca31b6f..3a86888a76cf5905a71c28a81601ca372cc622a5 100644 (file)
 
 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
 # define _GLIBCXX_LVAL_REF_QUAL &
+# define _GLIBCXX_SSTREAM_ALWAYS_INLINE
 #else
 # define _GLIBCXX_LVAL_REF_QUAL
+// For symbols that are not exported from libstdc++.so for the COW string ABI.
+# define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]]
 #endif
 
+
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -249,7 +254,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        return __ret;
       }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
       template<__allocator_like _SAlloc>
        basic_string<_CharT, _Traits, _SAlloc>
@@ -273,7 +279,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        _M_sync(_M_string.data(), 0, 0);
        return __str;
       }
+#endif // cxx11 ABI
 
+      _GLIBCXX_SSTREAM_ALWAYS_INLINE
       basic_string_view<char_type, traits_type>
       view() const noexcept
       {
@@ -696,7 +704,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       str() const _GLIBCXX_LVAL_REF_QUAL
       { return _M_stringbuf.str(); }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
       template<__allocator_like _SAlloc>
        basic_string<_CharT, _Traits, _SAlloc>
@@ -707,11 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       __string_type
       str() &&
       { return std::move(_M_stringbuf).str(); }
+#endif // cxx11 ABI
 
+      _GLIBCXX_SSTREAM_ALWAYS_INLINE
       basic_string_view<char_type, traits_type>
       view() const noexcept
       { return _M_stringbuf.view(); }
-#endif
+#endif // C++20
 
       /**
        *  @brief  Setting a new buffer.
@@ -917,7 +928,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       str() const _GLIBCXX_LVAL_REF_QUAL
       { return _M_stringbuf.str(); }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
       template<__allocator_like _SAlloc>
        basic_string<_CharT, _Traits, _SAlloc>
@@ -928,11 +940,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       __string_type
       str() &&
       { return std::move(_M_stringbuf).str(); }
+#endif // cxx11 ABI
 
+      _GLIBCXX_SSTREAM_ALWAYS_INLINE
       basic_string_view<char_type, traits_type>
       view() const noexcept
       { return _M_stringbuf.view(); }
-#endif
+#endif // C++20
 
       /**
        *  @brief  Setting a new buffer.
@@ -1136,7 +1150,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       str() const _GLIBCXX_LVAL_REF_QUAL
       { return _M_stringbuf.str(); }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
       template<__allocator_like _SAlloc>
        basic_string<_CharT, _Traits, _SAlloc>
@@ -1147,11 +1162,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       __string_type
       str() &&
       { return std::move(_M_stringbuf).str(); }
+#endif // cxx11 ABI
 
+      _GLIBCXX_SSTREAM_ALWAYS_INLINE
       basic_string_view<char_type, traits_type>
       view() const noexcept
       { return _M_stringbuf.view(); }
-#endif
+#endif // C++20
 
       /**
        *  @brief  Setting a new buffer.
@@ -1213,6 +1230,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
+#undef _GLIBCXX_SSTREAM_ALWAYS_INLINE
 #undef _GLIBCXX_LVAL_REF_QUAL
 
 #include <bits/sstream.tcc>
index a237b91afbaa30ba1ab38e948bbdd85c190282b8..bf559051f682f9819c625dea7a4ac3627de0d04b 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index b7f65b8a26bacbeabda3a22ac93b5a1276f1115b..3385e5d68b78aae5133148221e22ad9d8bc11561 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index b0e1ca579b196cf57f1a23ff0b53e59994b7790f..46206be802ea8271614e10de36d36fa02e850987 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index 508176c5583578226c36e65e9a81774261e886aa..e239a71d580d8f1043ecbea10da9aab8cbbd234b 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index 8e8440233ae0c7adec30ed25f7f58a706a4d21e5..908f349543b95e72d58f441e42115c66da714b22 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index 5c56c4a622a00fad456c2389f02d8a76d1490914..26b2fc0a1a42df8873388289bda07b0c9e26c99e 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index b6daaf6181b5c7f2ffa877a57e47fca36985a2b0..3f3af112d457c2338c951751abdb10fbde0b290a 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>
index b3a7f6e024f351c21737c28acac36aee8ce87640..d4fa96d43dc45bf6e86deed6a2ffc0af9dbed9f7 100644 (file)
@@ -19,7 +19,6 @@
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target cxx11_abi }
 
 #include <sstream>
 #include <string_view>