You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/01/08 07:01:39 UTC

[GitHub] [incubator-doris] vagetablechicken edited a comment on issue #2697: Using a range for loop and erasing an item may cause mem error

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:
users@infra.apache.org


With regards,
Apache Git Services

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