public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8700] libstdc++: Fix -Wdeprecated warning about implicit capture of 'this'
@ 2024-02-01 15:27 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-02-01 15:27 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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;
       }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-01 15:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 15:27 [gcc r14-8700] libstdc++: Fix -Wdeprecated warning about implicit capture of 'this' Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).