refactor: Avoid false-positive gcc warning

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<const char*, span<const char> >, char>((& kv)->std::span<const char>::begin(), (& kv)->std::span<const char>::end(), '=')’
  312 |         const auto& pos = std::find(kv.begin(), kv.end(), '=');
      |                           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
This commit is contained in:
MarcoFalke 2025-01-21 23:19:14 +01:00 committed by Lőrinc
parent 06a4d404ab
commit 73ff390b08

View File

@ -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 <chrono>
#include <memory>
#include <ranges>
#include <stdexcept>
#include <string>
@ -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 {