vagetablechicken edited a comment on issue #2697: Using a range for loop and 
erasing an item may cause mem error
URL: 
https://github.com/apache/incubator-doris/issues/2697#issuecomment-571913539
 
 
   Based on https://en.cppreference.com/w/cpp/language/range-for, I produce 
code equivalent to the following:
   ```
       for(auto beg=m.begin(), end=m.end(); beg !=end; ++beg){
           auto ita=(*beg).second.find(2);
           if(ita != (*beg).second.end()) (*beg).second.erase(2);
           if((*beg).second.empty()){
               m.erase((*beg).first);
           }
       }
   ```
   The valgrind report is the same like 'range for statement'.
   So I infer that using a range for loop and erasing an item can't avoid 
iterator invalidation. Although, I can't confirm how range for statement runs. 
Maybe the stl sources have the answer.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to