@@ -637,12 +637,14 @@ void CheckStlImpl::iterators()
637637void CheckStlImpl::mismatchingContainerIteratorError (const Token* containerTok, const Token* iterTok, const Token* containerTok2)
638638{
639639 const std::string container (containerTok ? containerTok->expressionString () : std::string (" v1" ));
640+ const std::string containerTemp (isTemporary (containerTok, &mSettings .library ) ? " temporary " : " " );
640641 const std::string container2 (containerTok2 ? containerTok2->expressionString () : std::string (" v2" ));
642+ const std::string containerTemp2 (isTemporary (containerTok2, &mSettings .library ) ? " temporary " : " " );
641643 const std::string iter (iterTok ? iterTok->expressionString () : std::string (" it" ));
642644 reportError (containerTok,
643645 Severity::error,
644646 " mismatchingContainerIterator" ,
645- " Iterator '" + iter + " ' referring to container '" + container2 + " ' is used with container '" + container + " '." ,
647+ " Iterator '" + iter + " ' referring to" + containerTemp2 + " container '" + container2 + " ' is used with" + containerTemp + " container '" + container + " '." ,
646648 CWE664 ,
647649 Certainty::normal);
648650}
@@ -884,7 +886,7 @@ void CheckStlImpl::mismatchingContainerIterator()
884886 const std::vector<const Token *> args = getArguments (ftok);
885887
886888 const Library::Container * c = tok->valueType ()->container ;
887- const Library::Container::Action action = c->getAction (tok-> strAt ( 2 ));
889+ const Library::Container::Action action = c->getAction (ftok-> str ( ));
888890 const Token* iterTok = nullptr ;
889891 if (action == Library::Container::Action::INSERT && args.size () == 2 ) {
890892 // Skip if iterator pair
@@ -3116,19 +3118,18 @@ void CheckStlImpl::useStlAlgorithm()
31163118 bool useLoopVarInMemCall;
31173119 const Token *memberAccessTok = singleMemberCallInScope (bodyTok, loopVar->varId (), useLoopVarInMemCall, mSettings );
31183120 if (memberAccessTok && loopType == LoopType::RANGE ) {
3119- const Token *memberCallTok = memberAccessTok->astOperand2 ();
31203121 const int contVarId = memberAccessTok->astOperand1 ()->varId ();
31213122 if (contVarId == loopVar->varId ())
31223123 continue ;
3123- if (memberCallTok-> str () == " push_back " ||
3124- memberCallTok-> str () == " push_front " ||
3125- memberCallTok-> str () == " emplace_back " ) {
3124+ using Action = Library::Container::Action;
3125+ const auto action = astContainerAction (memberAccessTok-> astOperand1 (), mSettings . library );
3126+ if ( contains ({Action:: PUSH , Action:: INSERT }, action) ) {
31263127 std::string algo;
31273128 if (useLoopVarInMemCall)
31283129 algo = " std::copy" ;
31293130 else
31303131 algo = " std::transform" ;
3131- useStlAlgorithmError (memberCallTok , algo);
3132+ useStlAlgorithmError (memberAccessTok-> astOperand2 () , algo);
31323133 }
31333134 continue ;
31343135 }
0 commit comments