Fix issue 8984: FP constStatement regression with qualified name (#1676)
This commit is contained in:
parent
6d0a1f80b4
commit
dfaf75db54
|
@ -1339,6 +1339,30 @@ void CheckOther::charBitOpError(const Token *tok)
|
|||
// Incomplete statement..
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static bool isType(const Token * tok, bool unknown)
|
||||
{
|
||||
if (Token::Match(tok, "%type%"))
|
||||
return true;
|
||||
if (Token::simpleMatch(tok, "::"))
|
||||
return isType(tok->astOperand2(), unknown);
|
||||
if (Token::simpleMatch(tok, "<") && tok->link())
|
||||
return true;
|
||||
if (unknown && Token::Match(tok, "%name% !!("))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isVarDeclOp(const Token* tok)
|
||||
{
|
||||
if (!tok)
|
||||
return false;
|
||||
const Token * vartok = tok->astOperand2();
|
||||
if (vartok && vartok->variable() && vartok->variable()->nameToken() == vartok)
|
||||
return true;
|
||||
const Token * typetok = tok->astOperand1();
|
||||
return isType(typetok, Token::Match(vartok, "%var%"));
|
||||
}
|
||||
|
||||
static bool isConstStatement(const Token *tok)
|
||||
{
|
||||
if (!tok)
|
||||
|
@ -1350,8 +1374,7 @@ static bool isConstStatement(const Token *tok)
|
|||
if (Token::Match(tok, "%var%"))
|
||||
return true;
|
||||
if (Token::Match(tok, "*|&|&&") &&
|
||||
(Token::Match(tok->previous(), "::|.") || Token::Match(tok->astOperand1(), "%type%") ||
|
||||
Token::Match(tok->astOperand2(), "%type%")))
|
||||
(Token::Match(tok->previous(), "::|.") || isVarDeclOp(tok)))
|
||||
return false;
|
||||
if (Token::Match(tok, "<<|>>") && !astIsIntegral(tok, false))
|
||||
return false;
|
||||
|
|
|
@ -84,6 +84,7 @@ private:
|
|||
TEST_CASE(mapindex);
|
||||
TEST_CASE(commaoperator);
|
||||
TEST_CASE(redundantstmts);
|
||||
TEST_CASE(vardecl);
|
||||
}
|
||||
|
||||
void test1() {
|
||||
|
@ -335,6 +336,27 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:1]: (warning) Unused variable value 'x'\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void vardecl() {
|
||||
// #8984
|
||||
check("void f() { a::b *c = d(); }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { std::vector<b> *c; }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { a::b &c = d(); }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { std::vector<b> &c; }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { a::b &&c = d(); }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { std::vector<b> &&c; }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestIncompleteStatement)
|
||||
|
|
Loading…
Reference in New Issue