[gcc r14-8700] libstdc++: Fix -Wdeprecated warning about implicit capture of 'this'

Jonathan Wakely redi@gcc.gnu.org
Thu Feb 1 15:27:22 GMT 2024


https://gcc.gnu.org/g:e81a69757720158fee81fc282cae02c4c82ab672

commit r14-8700-ge81a69757720158fee81fc282cae02c4c82ab672
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 23 15:35:29 2024 +0000

    libstdc++: Fix -Wdeprecated warning about implicit capture of 'this'
    
    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.

Diff:
---
 libstdc++-v3/include/experimental/internet | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet
index f04163dc4534..82043c87aca9 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -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;
       }


More information about the Libstdc++-cvs mailing list