Skip to content

Commit

Permalink
Fix warning and undefined behavior (AMReX-Codes#4236)
Browse files Browse the repository at this point in the history
* Move instead of copy.

* std::vector::erase invalidates the iterator, thus the original code
has undefined behavior in principle.
  • Loading branch information
WeiqunZhang authored Nov 18, 2024
1 parent 4210fe0 commit b98eaaf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Src/Base/AMReX_VisMF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ namespace
auto cached_ba = it->first.lock();
if (cached_ba) {
if (cached_ba->m_abox == ba_ref->m_abox) {
ba_ref = cached_ba;
ba_ref = std::move(cached_ba);
dm_ref = it->second.lock();
ielem = int(std::distance(s_layout_cache.begin(), it));
break;
}
++it;
} else { // expired
s_layout_cache.erase(it);
it = s_layout_cache.erase(it);
}
}

Expand Down

0 comments on commit b98eaaf

Please sign in to comment.