From 73ff390b0869d86f081c375d1c6efff60147917c Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 21 Jan 2025 23:19:14 +0100 Subject: [PATCH] refactor: Avoid false-positive gcc warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 14.2.1 will complain about a dangling reference after replacing Span wiht std::span. This is a false-positive, because std::find does not return a reference. Remove the `&` to silence the warning. Also use ranges::find while touching the line. src/i2p.cpp:312:21: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 312 | const auto& pos = std::find(kv.begin(), kv.end(), '='); | ^~~ src/i2p.cpp:312:36: note: the temporary was destroyed at the end of the full expression ‘std::find<__gnu_cxx::__normal_iterator >, char>((& kv)->std::span::begin(), (& kv)->std::span::end(), '=')’ 312 | const auto& pos = std::find(kv.begin(), kv.end(), '='); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors --- src/i2p.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/i2p.cpp b/src/i2p.cpp index 0420bc92382..156c8024339 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 The Bitcoin Core developers +// Copyright (c) 2020-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -309,7 +310,7 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock, reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE); for (const auto& kv : Split(reply.full, ' ')) { - const auto& pos = std::find(kv.begin(), kv.end(), '='); + const auto pos{std::ranges::find(kv, '=')}; if (pos != kv.end()) { reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()}); } else {