Fix unusedScopedObject FPs (#4364)
This commit is contained in:
parent
98b9f2cbf1
commit
1a95515e47
|
@ -2062,7 +2062,18 @@ void CheckOther::checkMisusedScopedObject()
|
||||||
&& Token::Match(tok->linkAt(2), ")|} ; !!}")
|
&& Token::Match(tok->linkAt(2), ")|} ; !!}")
|
||||||
&& (!tok->next()->function() || // is not a function on this scope
|
&& (!tok->next()->function() || // is not a function on this scope
|
||||||
tok->next()->function()->isConstructor()) // or is function in this scope and it's a ctor
|
tok->next()->function()->isConstructor()) // or is function in this scope and it's a ctor
|
||||||
&& (!tok->tokAt(2)->astOperand2() || isConstStatement(tok->tokAt(2)->astOperand2(), mTokenizer->isCPP()))) {
|
&& !Token::simpleMatch(tok->tokAt(2)->astParent(), ";")) { // for loop condition
|
||||||
|
if (const Token* arg = tok->tokAt(2)->astOperand2()) {
|
||||||
|
if (!isConstStatement(arg, mTokenizer->isCPP()))
|
||||||
|
continue;
|
||||||
|
if (tok->strAt(2) == "(") {
|
||||||
|
if (arg->varId()) // TODO: check if this is a declaration
|
||||||
|
continue;
|
||||||
|
const Token* rml = nextAfterAstRightmostLeaf(arg);
|
||||||
|
if (rml && rml->previous() && rml->previous()->varId())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
misusedScopeObjectError(tok, tok->str());
|
misusedScopeObjectError(tok, tok->str());
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -5049,6 +5049,17 @@ private:
|
||||||
"[test.cpp:7]: (style) Instance of 'int' object is destroyed immediately.\n"
|
"[test.cpp:7]: (style) Instance of 'int' object is destroyed immediately.\n"
|
||||||
"[test.cpp:8]: (style) Instance of 'int' object is destroyed immediately.\n",
|
"[test.cpp:8]: (style) Instance of 'int' object is destroyed immediately.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
check("void f(int j) {\n"
|
||||||
|
" for (; bool(j); ) {}\n"
|
||||||
|
"}\n", "test.cpp");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void g() {\n"
|
||||||
|
" float (f);\n"
|
||||||
|
" float (*p);\n"
|
||||||
|
"}\n", "test.cpp");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void trac2084() {
|
void trac2084() {
|
||||||
|
|
Loading…
Reference in New Issue