Fix uselessCallsConstructor TODOs (#4299)
* Fix uselessCallsConstructor TODOs * Format
This commit is contained in:
parent
a64a5e1496
commit
79f091c59a
|
@ -2175,9 +2175,19 @@ void CheckStl::uselessCalls()
|
|||
uselessCallsEmptyError(tok->next());
|
||||
else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument())
|
||||
uselessCallsRemoveError(tok->next(), tok->strAt(3));
|
||||
else if (printPerformance && Token::Match(tok, "%var% = { %var% . begin ( ) ,") &&
|
||||
tok->valueType() && tok->valueType()->type == ValueType::CONTAINER && tok->varId() == tok->tokAt(3)->varId()) {
|
||||
uselessCallsConstructorError(tok);
|
||||
else if (printPerformance && tok->valueType() && tok->valueType()->type == ValueType::CONTAINER) {
|
||||
if (Token::Match(tok, "%var% = { %var% . begin ( ) ,") && tok->varId() == tok->tokAt(3)->varId())
|
||||
uselessCallsConstructorError(tok);
|
||||
else if (const Variable* var = tok->variable()) {
|
||||
std::string pattern = "%var% = ";
|
||||
for (const Token* t = var->typeStartToken(); t != var->typeEndToken()->next(); t = t->next()) {
|
||||
pattern += t->str();
|
||||
pattern += ' ';
|
||||
}
|
||||
pattern += "{|( %varid% . begin ( ) ,";
|
||||
if (Token::Match(tok, pattern.c_str(), tok->varId()))
|
||||
uselessCallsConstructorError(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4202,17 +4202,22 @@ private:
|
|||
" s = std::string{ s.begin(), s.begin() + end };\n"
|
||||
" return s;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n",
|
||||
"",
|
||||
errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n",
|
||||
errout.str());
|
||||
|
||||
check("std::string f(std::string s, std::size_t end) {\n"
|
||||
" s = std::string(s.begin(), s.begin() + end);\n"
|
||||
" return s;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n",
|
||||
"",
|
||||
errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n",
|
||||
errout.str());
|
||||
|
||||
check("std::vector<int> f(std::vector<int> v, std::size_t end) {\n"
|
||||
" v = std::vector<int>(v.begin(), v.begin() + end);\n"
|
||||
" return v;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void stabilityOfChecks() {
|
||||
|
|
Loading…
Reference in New Issue