Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ void CheckStl::useStlAlgorithm()
algo = "std::copy";
else
algo = "std::transform";
useStlAlgorithmError(assignTok, algo);
useStlAlgorithmError(memberCallTok, algo);
}
continue;
}
Expand Down
12 changes: 6 additions & 6 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3324,47 +3324,47 @@ class TestStl : public TestFixture {
" c.push_back(x);\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::copy algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::copy algorithm instead of a raw loop.\n", errout.str());

check("void foo() {\n"
" std::vector<int> c;\n"
" for(int x:v)\n"
" c.push_back(f(x));\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());

check("void foo() {\n"
" std::vector<int> c;\n"
" for(int x:v)\n"
" c.push_back(x + 1);\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());

check("void foo() {\n"
" std::vector<int> c;\n"
" for(int x:v)\n"
" c.push_front(x);\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::copy algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::copy algorithm instead of a raw loop.\n", errout.str());

check("void foo() {\n"
" std::vector<int> c;\n"
" for(int x:v)\n"
" c.push_front(f(x));\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());

check("void foo() {\n"
" std::vector<int> c;\n"
" for(int x:v)\n"
" c.push_front(x + 1);\n"
"}\n",
true);
ASSERT_EQUALS("(style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout.str());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop starts in line 3 - though the trigger for the message is the content which is in line 4.
In case of nested loops the message could be ambiguous.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, all the messages point inside the loops, so its consistent with the other useStlAlgorithm messages. I can update the messages in another PR. This is mainly to fix the problem with messages that have no location for them.


check("void foo() {\n"
" std::vector<int> c;\n"
Expand Down