Skip to content

Commit fa4d6ec

Browse files
author
MarcoFalke
committed
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
1 parent fa94233 commit fa4d6ec

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/i2p.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2022 The Bitcoin Core developers
1+
// Copyright (c) 2020-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -23,6 +23,7 @@
2323

2424
#include <chrono>
2525
#include <memory>
26+
#include <ranges>
2627
#include <stdexcept>
2728
#include <string>
2829

@@ -309,7 +310,7 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
309310
reply.full = sock.RecvUntilTerminator('\n', recv_timeout, *m_interrupt, MAX_MSG_SIZE);
310311

311312
for (const auto& kv : Split(reply.full, ' ')) {
312-
const auto& pos = std::find(kv.begin(), kv.end(), '=');
313+
const auto pos{std::ranges::find(kv, '=')};
313314
if (pos != kv.end()) {
314315
reply.keys.emplace(std::string{kv.begin(), pos}, std::string{pos + 1, kv.end()});
315316
} else {

0 commit comments

Comments
 (0)