Fix dangling reference warnings about refs to iterators

These are causing warnings with GCC-14.

An iterator can often be a struct containing a single pointer, so
creating a reference to such a small struct doesn't make sense.

The structure returned by child_range is likely to be exactly two
pointers, so it's not a burden to keep it even though back() has
already finished accessing the child_iterator.

(cherry picked from commit 087fa65dc5)
This commit is contained in:
Steve Cotton 2024-06-14 14:42:18 +02:00 committed by Steve Cotton
parent 791eed42cf
commit 1c9e3f220c
2 changed files with 3 additions and 2 deletions

View file

@ -63,7 +63,8 @@ void unit_advance::pre_show(window& window)
// This checks if we've finished iterating over the last unit type advancements
// and are into the modification-based advancements.
if(i >= last_real_advancement_) {
const auto& back = sample.get_modifications().child_range("advancement").back();
const auto range = sample.get_modifications().child_range("advancement");
const auto& back = range.back();
if(back.has_attribute("image")) {
image_string = back["image"].str();

View file

@ -1313,7 +1313,7 @@ const topic *find_topic(const section &sec, const std::string &id)
const section *find_section(const section &sec, const std::string &id)
{
const auto &sit =
const auto sit =
std::find_if(sec.sections.begin(), sec.sections.end(), has_id(id));
if (sit != sec.sections.end()) {
return &*sit;