]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix -Wdeprecated warning about implicit capture of 'this'
authorJonathan Wakely <jwakely@redhat.com>
Tue, 23 Jan 2024 15:35:29 +0000 (15:35 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 1 Feb 2024 15:26:53 +0000 (15:26 +0000)
In C++20 it's deprecated for a [=] lambda capture to capture the 'this'
pointer. Using resize_and_overwrite with a lambda seems like overkill to
write three chars to the string anyway. Just resize the string and
overwrite the end of it directly.

libstdc++-v3/ChangeLog:

* include/experimental/internet (network_v4::to_string()):
Remove lambda and use of resize_and_overwrite.

libstdc++-v3/include/experimental/internet

index f04163dc4534f0ee5a3f4be447b844e5802047fd..82043c87aca9f5e029ab1f1814c18f9575567227 100644 (file)
@@ -1314,20 +1314,12 @@ namespace ip
       {
        auto __str = address().to_string(__a);
        const unsigned __addrlen = __str.length();
-       const unsigned __preflen = prefix_length() >= 10 ? 2 : 1;
-       auto __write = [=](char* __p, size_t __n) {
-         __p[__addrlen] = '/';
-         std::__detail::__to_chars_10_impl(__p + __addrlen + 1, __preflen,
-                                           (unsigned char)prefix_length());
-         return __n;
-       };
-       const unsigned __len = __addrlen + 1 + __preflen;
-#if __cpp_lib_string_resize_and_overwrite
-       __str.resize_and_overwrite(__len, __write);
-#else
-       __str.resize(__len);
-       __write(&__str.front(), __len);
-#endif
+       const unsigned __preflenlen = _M_prefix_len >= 10 ? 2 : 1;
+       __str.resize(__addrlen + 1 + __preflenlen);
+       __str[__addrlen] = '/';
+       std::__detail::__to_chars_10_impl(&__str.front() + __addrlen + 1,
+                                         __preflenlen,
+                                         (unsigned char)_M_prefix_len);
        return __str;
       }