parent
212ac6c214
commit
796ad6c008
|
@ -1065,7 +1065,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
||||||
if (!bFirstAssignment && Token::Match(tok, "* %varid%", var->declarationId())) // dereferencing means access to previous content
|
if (!bFirstAssignment && Token::Match(tok, "* %varid%", var->declarationId())) // dereferencing means access to previous content
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Token::Match(tok, "= %varid%", var->declarationId()) && (var->isArray() || var->isPointer())) // Create a copy of array/pointer. Bailout, because the memory it points to might be necessary in outer scope
|
if (Token::Match(tok, "= %varid%", var->declarationId()) && (var->isArray() || var->isPointer() || (var->valueType() && var->valueType()->container))) // Create a copy of array/pointer. Bailout, because the memory it points to might be necessary in outer scope
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (tok->varId() == var->declarationId()) {
|
if (tok->varId() == var->declarationId()) {
|
||||||
|
|
|
@ -1346,6 +1346,19 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 's' can be reduced.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 's' can be reduced.\n", errout.str());
|
||||||
|
|
||||||
|
check("auto foo(std::vector<int>& vec, bool flag) {\n"
|
||||||
|
" std::vector<int> dummy;\n"
|
||||||
|
" std::vector<int>::iterator iter;\n"
|
||||||
|
" if (flag)\n"
|
||||||
|
" iter = vec.begin();\n"
|
||||||
|
" else {\n"
|
||||||
|
" dummy.push_back(42);\n"
|
||||||
|
" iter = dummy.begin();\n"
|
||||||
|
" }\n"
|
||||||
|
" return *iter;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void varScope30() { // #8541
|
void varScope30() { // #8541
|
||||||
|
|
Loading…
Reference in New Issue