@@ -7498,8 +7498,8 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
74987498 }))
74997499 return Action::Read | Action::Write | Action::Incremental;
75007500 }
7501- } else if (Token::Match (tok, " %name% . %name% (" )) {
7502- Library::Container::Action action = container->getAction (tok->strAt (2 ));
7501+ } else if (astIsLHS (tok) && Token::Match (tok-> astParent () , " . %name% (" )) {
7502+ Library::Container::Action action = container->getAction (tok->astParent ()-> strAt (1 ));
75037503 if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP ) {
75047504 std::vector<const Token*> args = getArguments (tok->tokAt (3 ));
75057505 if (args.size () < 2 )
@@ -7535,8 +7535,8 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
75357535 }
75367536 }
75377537 }
7538- } else if (Token::Match (tok, " %name% . %name% (" )) {
7539- Library::Container::Action action = container->getAction (tok->strAt (2 ));
7538+ } else if (astIsLHS (tok) && Token::Match (tok-> astParent () , " . %name% (" )) {
7539+ Library::Container::Action action = container->getAction (tok->astParent ()-> strAt (1 ));
75407540 if (action == Library::Container::Action::PUSH )
75417541 val->intvalue ++;
75427542 if (action == Library::Container::Action::POP )
@@ -7661,29 +7661,34 @@ bool isContainerSizeChanged(const Token* tok, const Settings* settings, int dept
76617661 return false ;
76627662 if (!tok->valueType () || !tok->valueType ()->container )
76637663 return true ;
7664- if (Token::Match (tok, " %name% %assign%|<<" ))
7664+ if (astIsLHS (tok) && Token::Match (tok-> astParent () , " %assign%|<<" ))
76657665 return true ;
7666- if (Token::Match (tok, " %var% [" ) && tok->valueType ()->container ->stdAssociativeLike )
7666+ const Library::Container* container = tok->valueType ()->container ;
7667+ // Views cannot change container size
7668+ if (container->view )
7669+ return false ;
7670+ if (astIsLHS (tok) && Token::simpleMatch (tok->astParent (), " [" ))
7671+ return container->stdAssociativeLike ;
7672+ Library::Container::Action action = astContainerAction (tok);
7673+ Library::Container::Yield yield = astContainerYield (tok);
7674+ switch (action) {
7675+ case Library::Container::Action::RESIZE :
7676+ case Library::Container::Action::CLEAR :
7677+ case Library::Container::Action::PUSH :
7678+ case Library::Container::Action::POP :
7679+ case Library::Container::Action::CHANGE :
7680+ case Library::Container::Action::INSERT :
7681+ case Library::Container::Action::ERASE :
76677682 return true ;
7668- if (Token::Match (tok, " %name% . %name% (" )) {
7669- Library::Container::Action action = tok->valueType ()->container ->getAction (tok->strAt (2 ));
7670- Library::Container::Yield yield = tok->valueType ()->container ->getYield (tok->strAt (2 ));
7671- switch (action) {
7672- case Library::Container::Action::RESIZE :
7673- case Library::Container::Action::CLEAR :
7674- case Library::Container::Action::PUSH :
7675- case Library::Container::Action::POP :
7676- case Library::Container::Action::CHANGE :
7677- case Library::Container::Action::INSERT :
7678- case Library::Container::Action::ERASE :
7679- return true ;
7680- case Library::Container::Action::NO_ACTION : // might be unknown action
7683+ case Library::Container::Action::NO_ACTION :
7684+ // Is this an unknown member function call?
7685+ if (astIsLHS (tok) && Token::Match (tok->astParent (), " . %name% (" ))
76817686 return yield == Library::Container::Yield::NO_YIELD ;
7682- case Library::Container::Action:: FIND :
7683- case Library::Container::Action::CHANGE_CONTENT :
7684- case Library::Container::Action::CHANGE_INTERNAL :
7685- break ;
7686- }
7687+ break ;
7688+ case Library::Container::Action::FIND :
7689+ case Library::Container::Action::CHANGE_CONTENT :
7690+ case Library::Container::Action:: CHANGE_INTERNAL :
7691+ break ;
76877692 }
76887693 if (isContainerSizeChangedByFunction (tok, settings, depth))
76897694 return true ;
@@ -7795,16 +7800,17 @@ static void valueFlowIterators(TokenList *tokenlist, const Settings *settings)
77957800 continue ;
77967801 if (!astIsContainer (tok))
77977802 continue ;
7798- if (Token::Match (tok->astParent (), " . %name% (" )) {
7799- Library::Container::Yield yield = getLibraryContainer (tok)->getYield (tok->astParent ()->strAt (1 ));
7803+ const Token* ftok = nullptr ;
7804+ Library::Container::Yield yield = astContainerYield (tok, &ftok);
7805+ if (ftok) {
78007806 ValueFlow::Value v (0 );
78017807 v.setKnown ();
78027808 if (yield == Library::Container::Yield::START_ITERATOR ) {
78037809 v.valueType = ValueFlow::Value::ValueType::ITERATOR_START ;
7804- setTokenValue (tok-> astParent ()-> tokAt ( 2 ), v, settings);
7810+ setTokenValue (ftok-> next ( ), v, settings);
78057811 } else if (yield == Library::Container::Yield::END_ITERATOR ) {
78067812 v.valueType = ValueFlow::Value::ValueType::ITERATOR_END ;
7807- setTokenValue (tok-> astParent ()-> tokAt ( 2 ), v, settings);
7813+ setTokenValue (ftok-> next ( ), v, settings);
78087814 }
78097815 }
78107816 }
0 commit comments