File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,6 +165,20 @@ void CheckStl::iterators()
165165 if (itTok->previous ()->str () == " *" )
166166 continue ;
167167
168+ // inserting iterator range..
169+ if (tok2->strAt (2 ) == " insert" ) {
170+ const Token *par2 = itTok->nextArgument ();
171+ while (par2 && par2->str () != " )" ) {
172+ if (par2->varId () == container->declarationId ())
173+ break ;
174+ if (par2->str () == " (" )
175+ par2 = par2->link ();
176+ par2 = par2->next ();
177+ }
178+ if (par2->varId () == container->declarationId ())
179+ continue ;
180+ }
181+
168182 // Show error message, mismatching iterator is used.
169183 iteratorsError (tok2, container->name (), tok2->str ());
170184 }
Original file line number Diff line number Diff line change @@ -201,6 +201,14 @@ class TestStl : public TestFixture {
201201 " l2.insert(it, 0);\n "
202202 " }" );
203203 ASSERT_EQUALS (" [test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n " , errout.str ());
204+
205+ check (" void foo() {\n " // #5803
206+ " list<int> l1;\n "
207+ " list<int> l2;\n "
208+ " list<int>::iterator it = l1.begin();\n "
209+ " l2.insert(it, l1.end());\n "
210+ " }" );
211+ ASSERT_EQUALS (" " , errout.str ());
204212 }
205213
206214 void iterator4 () {
You can’t perform that action at this time.
0 commit comments