[1/7] gdb: clear other.m_cached_id in frame_info_ptr's move ctor

Message ID 20221107155310.2590069-1-simon.marchi@polymtl.ca
State Committed
Commit 70f479c6f8bf976ca680fd53d655ccec56b3f12e
Headers
Series [1/7] gdb: clear other.m_cached_id in frame_info_ptr's move ctor |

Commit Message

Simon Marchi Nov. 7, 2022, 3:53 p.m. UTC
  We do it in the move assignment operator, so I think it makes sense to
do it here too for consistency.  I don't think it's absolutely necessary
to clear the other object's fields (in other words, copy constructor and
move constructor could be the same), as there is no exclusive resource
being transfered.  The important thing is to leave the moved-from object
in an unknown, but valid state.  But still, I think that clearing the
fields of the moved-from object is not a bad idea, it helps ensure we
don't rely on the moved-from object after.

Change-Id: Iee900ff9d25dad51d62765d694f2e01524351340
---
 gdb/frame-info.h | 1 +
 1 file changed, 1 insertion(+)


base-commit: 240e07bd94a8da9270c57cde394f6883e43b8497
  

Comments

Guinevere Larsen Nov. 8, 2022, 8:53 a.m. UTC | #1
On 07/11/2022 16:53, Simon Marchi via Gdb-patches wrote:
> We do it in the move assignment operator, so I think it makes sense to
> do it here too for consistency.  I don't think it's absolutely necessary
> to clear the other object's fields (in other words, copy constructor and
> move constructor could be the same), as there is no exclusive resource
> being transfered.  The important thing is to leave the moved-from object
> in an unknown, but valid state.  But still, I think that clearing the
> fields of the moved-from object is not a bad idea, it helps ensure we
> don't rely on the moved-from object after.
>
> Change-Id: Iee900ff9d25dad51d62765d694f2e01524351340

Seems obvious enough.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
  

Patch

diff --git a/gdb/frame-info.h b/gdb/frame-info.h
index 665f4bdae3bf..7159f82b1962 100644
--- a/gdb/frame-info.h
+++ b/gdb/frame-info.h
@@ -71,6 +71,7 @@  class frame_info_ptr : public intrusive_list_node<frame_info_ptr>
     : m_ptr (other.m_ptr), m_cached_id (other.m_cached_id)
   {
     other.m_ptr = nullptr;
+    other.m_cached_id = null_frame_id;
     frame_list.push_back (*this);
   }