[libcxx-commits] [libcxx] 4822447 - [libc++] basic_string::resize_and_overwrite: Adopt LWG3645 (Not voted in yet)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 20 09:42:47 PST 2022


Author: Nikolas Klauser
Date: 2022-01-20T18:41:09+01:00
New Revision: 48224475222d14e6f661d649f4363dcc197cc7ef

URL: https://github.com/llvm/llvm-project/commit/48224475222d14e6f661d649f4363dcc197cc7ef
DIFF: https://github.com/llvm/llvm-project/commit/48224475222d14e6f661d649f4363dcc197cc7ef.diff

LOG: [libc++] basic_string::resize_and_overwrite: Adopt LWG3645 (Not voted in yet)

Adopt LWG3645, which fixes the value categories of basic_string::resize_and_overwrite
https://timsong-cpp.github.io/lwg-issues/3645

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116815

Added: 
    

Modified: 
    libcxx/docs/Status/Cxx2bIssues.csv
    libcxx/include/string
    libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 1a8f6a4792c1..726668f3bdb2 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -137,3 +137,5 @@
 `3593 <https://wg21.link/LWG3593>`__,"Several iterators' ``base() const &`` and ``lazy_split_view::outer-iterator::value_type::end()`` missing ``noexcept``","October 2021","","","|ranges|"
 `3595 <https://wg21.link/LWG3595>`__,"Exposition-only classes proxy and postfix-proxy for ``common_iterator`` should be fully ``constexpr``","October 2021","","","|ranges|"
 "","","","",""
+`3645 <https://wg21.link/LWG3645>`__,"``resize_and_overwrite`` is overspecified to call its callback with lvalues", "Not voted in","|Complete|","14.0",""
+"","","","",""
\ No newline at end of file

diff  --git a/libcxx/include/string b/libcxx/include/string
index c4f2b008cafe..b2eef646f982 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -979,8 +979,7 @@ public:
     _LIBCPP_HIDE_FROM_ABI constexpr
     void resize_and_overwrite(size_type __n, _Op __op) {
       __resize_default_init(__n);
-      pointer __data = data();
-      __erase_to_end(_VSTD::move(__op)(__data, __n));
+      __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
     }
 #endif
 

diff  --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
index 3f97537dd2df..61312fa5ec49 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
@@ -76,7 +76,8 @@ constexpr bool test() {
 
 void test_value_categories() {
   std::string s;
-  s.resize_and_overwrite(10, [](char*&, size_t&) { return 0; });
+  s.resize_and_overwrite(10, [](char*&&, size_t&&) { return 0; });
+  s.resize_and_overwrite(10, [](char* const&, const size_t&) { return 0; });
   struct RefQualified {
     int operator()(char*, size_t) && { return 0; }
   };


        


More information about the libcxx-commits mailing list