From 79f6a43c5fbd1f28f2fbdaa642cf42a0079b5be6 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 13 Oct 2019 23:53:12 +0200 Subject: Fix lifetime issue for Entry objects. --- src/entry.cpp | 35 ++++++++++++++++++++++++++--------- src/entry.h | 5 ++++- src/scanner.l | 4 ++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/entry.cpp b/src/entry.cpp index ec3c736..8ec7846 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -240,6 +240,32 @@ void Entry::copyToSubEntry(const std::unique_ptr ¤t) m_sublist.push_back(std::move(copy)); } +void Entry::moveFromSubEntry(const Entry *child,std::unique_ptr &moveTo) +{ + auto it = std::find_if(m_sublist.begin(),m_sublist.end(), + [child](const std::unique_ptr&elem) { return elem.get()==child; }); + if (it!=m_sublist.end()) + { + moveTo = std::move(*it); + m_sublist.erase(it); + } + else + { + moveTo.reset(); + } +} + +void Entry::removeSubEntry(const Entry *e) +{ + auto it = std::find_if(m_sublist.begin(),m_sublist.end(), + [e](const std::unique_ptr&elem) { return elem.get()==e; }); + if (it!=m_sublist.end()) + { + m_sublist.erase(it); + } +} + + void Entry::reset() { static bool entryCallGraph = Config_getBool(CALL_GRAPH); @@ -335,14 +361,5 @@ void Entry::addSpecialListItem(const char *listName,int itemId) sli->append(ili); } -void Entry::removeSubEntry(Entry *e) -{ - auto it = std::find_if(m_sublist.begin(),m_sublist.end(), - [e](const std::unique_ptr&elem) { return elem.get()==e; }); - if (it!=m_sublist.end()) - { - m_sublist.erase(it); - } -} //------------------------------------------------------------------ diff --git a/src/entry.h b/src/entry.h index 091e81b..c078936 100644 --- a/src/entry.h +++ b/src/entry.h @@ -223,6 +223,9 @@ class Entry void moveToSubEntryAndRefresh(Entry* &e); void moveToSubEntryAndRefresh(std::unique_ptr &e); + /*! take \a child of of to list of children and move it into \a moveTo */ + void moveFromSubEntry(const Entry *child,std::unique_ptr &moveTo); + /*! make a copy of \a e and add it as a child to this entry */ void copyToSubEntry (Entry* e); void copyToSubEntry (const std::unique_ptr &e); @@ -230,7 +233,7 @@ class Entry /*! Removes entry \a e from the list of children. * The entry will be deleted if found. */ - void removeSubEntry(Entry *e); + void removeSubEntry(const Entry *e); /*! Restore the state of this Entry to the default value it has * at construction time. diff --git a/src/scanner.l b/src/scanner.l index fe20543..4ed4a62 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -5305,9 +5305,9 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) else { current->endBodyLine=yyLineNr; - + // take previous out of current_root and move it into current current.swap(tempEntry); // remember current - current.reset(previous); // and temporarily switch to the previous entry + current_root->moveFromSubEntry(previous,current); previous = 0; docBlockContext = SkipCurlyEndDoc; -- cgit v0.12