]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement LWG 3706 for COW strings
authorJonathan Wakely <jwakely@redhat.com>
Wed, 14 Oct 2020 10:52:26 +0000 (11:52 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 20 Oct 2020 17:52:32 +0000 (18:52 +0100)
The basic_string deduction guides are defined for the old ABI, but the
tests are currently disabled. This is because a single case fails when
using the old ABI, which is just because LWG 3706 isn't implemented for
the old ABI. That can be done easily, and the tests can be enabled.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI]
(basic_string(const _CharT*, const _Alloc&)): Constrain to
require an allocator-like type to fix CTAD ambiguity (LWG 3706).
Define inline.
* include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]
(basic_string(const _CharT*, const _Alloc&)): Remove non-inline
definition.
* testsuite/21_strings/basic_string/cons/char/deduction.cc:
Remove dg-skip-if.
* testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc:
Likewise.

(cherry picked from commit dc38e255242192303ae463a913c060b426eb06c0)

libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc
libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc

index bc0c256b65e4893ed6dba1f29557ec5310e49aeb..bbab7b9d4d22487bcfe96fc080ea1dc48cb5b3cb 100644 (file)
@@ -3605,12 +3605,22 @@ _GLIBCXX_END_NAMESPACE_CXX11
        */
       basic_string(const _CharT* __s, size_type __n,
                   const _Alloc& __a = _Alloc());
+
       /**
        *  @brief  Construct string as copy of a C string.
        *  @param  __s  Source C string.
        *  @param  __a  Allocator to use (default is default allocator).
        */
-      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
+#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 3076. basic_string CTAD ambiguity
+      template<typename = _RequireAllocator<_Alloc>>
+#endif
+      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
+      : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
+                                 __s + npos, __a), __a)
+      { }
+
       /**
        *  @brief  Construct string as multiple characters.
        *  @param  __n  Number of characters.
index e370f439390f94903988478a3c9bf36c169d94f5..204a140a735461757b7da3674d157de76c851d98 100644 (file)
@@ -659,14 +659,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
     { }
 
-  // TBD: DPG annotate
-  template<typename _CharT, typename _Traits, typename _Alloc>
-    basic_string<_CharT, _Traits, _Alloc>::
-    basic_string(const _CharT* __s, const _Alloc& __a)
-    : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
-                              __s + npos, __a), __a)
-    { }
-
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_string<_CharT, _Traits, _Alloc>::
     basic_string(size_type __n, _CharT __c, const _Alloc& __a)
index 6484ed4345335e00b941f791f31731741eb2aef5..d05c4b776c32031af1076a00abda758ba38a534c 100644 (file)
@@ -17,7 +17,6 @@
 
 // { dg-options "-std=gnu++17" }
 // { dg-do compile { target c++17 } }
-// { dg-xfail-if "COW string missing deduction guides" { ! cxx11-abi } }
 
 #include <string>
 #include <testsuite_iterators.h>
index 373b2b24bdd9affd4dcb46aa22ca6ba05103c2ef..1773be28e3778b4a9dd2b4690f823d6b6cf345f5 100644 (file)
@@ -17,7 +17,6 @@
 
 // { dg-options "-std=gnu++17" }
 // { dg-do compile { target c++17 } }
-// { dg-xfail-if "COW string missing deduction guides" { ! cxx11-abi } }
 
 #include <string>
 #include <testsuite_iterators.h>