Fix issue 8984: FP constStatement regression with qualified name (#1676)

This commit is contained in:
Paul Fultz II 2019-02-19 00:08:36 -06:00 committed by Daniel Marjamäki
parent 6d0a1f80b4
commit dfaf75db54
2 changed files with 47 additions and 2 deletions

View File

@ -1339,6 +1339,30 @@ void CheckOther::charBitOpError(const Token *tok)
// Incomplete statement.. // 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) static bool isConstStatement(const Token *tok)
{ {
if (!tok) if (!tok)
@ -1350,8 +1374,7 @@ static bool isConstStatement(const Token *tok)
if (Token::Match(tok, "%var%")) if (Token::Match(tok, "%var%"))
return true; return true;
if (Token::Match(tok, "*|&|&&") && if (Token::Match(tok, "*|&|&&") &&
(Token::Match(tok->previous(), "::|.") || Token::Match(tok->astOperand1(), "%type%") || (Token::Match(tok->previous(), "::|.") || isVarDeclOp(tok)))
Token::Match(tok->astOperand2(), "%type%")))
return false; return false;
if (Token::Match(tok, "<<|>>") && !astIsIntegral(tok, false)) if (Token::Match(tok, "<<|>>") && !astIsIntegral(tok, false))
return false; return false;

View File

@ -84,6 +84,7 @@ private:
TEST_CASE(mapindex); TEST_CASE(mapindex);
TEST_CASE(commaoperator); TEST_CASE(commaoperator);
TEST_CASE(redundantstmts); TEST_CASE(redundantstmts);
TEST_CASE(vardecl);
} }
void test1() { void test1() {
@ -335,6 +336,27 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (warning) Unused variable value 'x'\n", errout.str()); 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) REGISTER_TEST(TestIncompleteStatement)