]> 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>
Thu, 2 Feb 2023 16:57:27 +0000 (16:57 +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_0stringstream::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.

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 4f0c50fcc8a7499cb4395426115a3eadb770caf9..6b3139714c7333b63e6c1bdb118802a2cb56ef84 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
@@ -251,7 +256,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>
@@ -275,7 +281,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
       {
@@ -698,7 +706,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>
@@ -709,11 +718,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.
@@ -919,7 +930,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>
@@ -930,11 +942,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.
@@ -1138,7 +1152,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>
@@ -1149,11 +1164,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.
@@ -1215,6 +1232,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 5309c448be2e6c933df4c56646cebe790728ac82..04aae8175692612e7b56f0dd3f3a923ee6f597cd 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 774bef10fc53da2baa6c2f3ed7ddebe2b999b3a5..06b04b3c6b97b77a86953a7ea5cadee47e9dc4c0 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 320086153ff4e29cd140f1479a59a65ee88643da..41279083a06f15eb446ee2d42f4e63ac46820fe0 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 1b9b851eb2594332fbd5ddcf6886d62196187350..2f177d45d7064be5079d36dcc1391e6991422c6d 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 998ad5c3e2b324cbdd52092a017dc616036c358f..138f4b124e555fc64eb6d82cc4d0aa69c0fb5a0d 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 58334084dc1aa76cad910bb16305a031d7f7ec15..30b8f0549f40df4cc57ad4a3567f80d1553c1a87 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 bd14bc58293a440d9e12e1bdc19e109e17edbb92..91d329dfa86cbdc331c9501489ce58c4caf098ae 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 d179f4e220166b87a9e6330d72d37140ae2af342..7af53dcd16f172ca69fb6446f11ef7caacc629f0 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>