Incomplete statement: Fix FP for 'ar & x'

This commit is contained in:
Daniel Marjamäki 2019-03-31 11:50:57 +02:00
parent 73433c2961
commit 29a5404d1e
2 changed files with 16 additions and 0 deletions

View File

@ -1443,6 +1443,9 @@ void CheckOther::checkIncompleteStatement()
continue;
if (isVoidStmt(tok))
continue;
if (mTokenizer->isCPP() && tok->str() == "&" && !(tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isIntegral()))
// Possible archive
continue;
bool inconclusive = Token::Match(tok, "%cop%");
if (mSettings->inconclusive || !inconclusive)
constStatementError(tok, tok->isNumber() ? "numeric" : "string", inconclusive);

View File

@ -85,6 +85,7 @@ private:
TEST_CASE(commaoperator);
TEST_CASE(redundantstmts);
TEST_CASE(vardecl);
TEST_CASE(archive); // ar & x
}
void test1() {
@ -366,6 +367,18 @@ private:
check("void f() { char * const * a = 0, * volatile const * b; }", true);
ASSERT_EQUALS("", errout.str());
}
void archive() {
check("void f(Archive &ar) {\n"
" ar & x;\n"
"}", true);
ASSERT_EQUALS("", errout.str());
check("void f(int ar) {\n"
" ar & x;\n"
"}", true);
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '&'\n", errout.str());
}
};
REGISTER_TEST(TestIncompleteStatement)