libstdc++: Fix fully-dynamic-string build
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Nov 2021 12:54:10 +0000 (12:54 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 30 Nov 2021 23:10:03 +0000 (23:10 +0000)
My last change to the fully-dynamic-string actually broke it. This fixes
the move constructor so it builds, and simplifies it slightly so that
more code is common between the fully-dynamic enabled/disabled cases.

libstdc++-v3/ChangeLog:

* include/bits/cow_string.h (basic_string(basic_string&&)): Fix
mem-initializer for _GLIBCXX_FULLY_DYNAMIC_STRING==0 case.
* testsuite/21_strings/basic_string/cons/char/noexcept_move_construct.cc:
Remove outdated comment.
* testsuite/21_strings/basic_string/cons/wchar_t/noexcept_move_construct.cc:
Likewise.

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

index bafca7b..ced395b 100644 (file)
@@ -621,14 +621,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @a __str is a valid, but unspecified string.
        */
       basic_string(basic_string&& __str) noexcept
-#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
       : _M_dataplus(std::move(__str._M_dataplus))
       {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
+       // Make __str use the shared empty string rep.
        __str._M_data(_S_empty_rep()._M_refdata());
-      }
 #else
-      : _M_dataplus(__str._M_rep())
-      {
        // Rather than allocate an empty string for the rvalue string,
        // just share ownership with it by incrementing the reference count.
        // If the rvalue string was "leaked" then it was the unique owner,
@@ -637,8 +635,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 2);
        else
          __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
-      }
 #endif
+      }
 
       /**
        *  @brief  Construct string from an initializer %list.
index f04a491..74b0ed3 100644 (file)
@@ -23,7 +23,6 @@
 
 typedef std::string stype;
 
-// True except for COW strings with _GLIBCXX_FULLY_DYNAMIC_STRING:
 static_assert(std::is_nothrow_move_constructible<stype>::value, "Error");
 
 // True for std::allocator because is_always_equal, but not true in general:
index d5dbf56..53cb81d 100644 (file)
@@ -23,7 +23,6 @@
 
 typedef std::wstring wstype;
 
-// True except for COW strings with _GLIBCXX_FULLY_DYNAMIC_STRING:
 static_assert(std::is_nothrow_move_constructible<wstype>::value, "Error");
 
 // True for std::allocator because is_always_equal, but not true in general: