Fix FP with unused variable (#1814)

This commit is contained in:
Paul Fultz II 2019-04-29 04:50:19 -05:00 committed by Daniel Marjamäki
parent 2e694f38c8
commit ae8a3aae8d
3 changed files with 13 additions and 1 deletions

View File

@ -483,7 +483,7 @@ static bool iscpp11init(const Token * const tok)
endtok = nameToken->linkAt(1)->linkAt(1); endtok = nameToken->linkAt(1)->linkAt(1);
else else
return false; return false;
if (Token::Match(nameToken, "else|try|do")) if (Token::Match(nameToken, "else|try|do|const|override|volatile|&|&&"))
return false; return false;
// There is no initialisation for example here: 'class Fred {};' // There is no initialisation for example here: 'class Fred {};'
if (!Token::simpleMatch(endtok, "} ;")) if (!Token::simpleMatch(endtok, "} ;"))

View File

@ -86,6 +86,7 @@ private:
TEST_CASE(redundantstmts); TEST_CASE(redundantstmts);
TEST_CASE(vardecl); TEST_CASE(vardecl);
TEST_CASE(archive); // ar & x TEST_CASE(archive); // ar & x
TEST_CASE(ast);
} }
void test1() { void test1() {
@ -379,6 +380,11 @@ private:
"}", true); "}", true);
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '&'\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '&'\n", errout.str());
} }
void ast() {
check("struct c { void a() const { for (int x=0; x;); } };", true);
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestIncompleteStatement) REGISTER_TEST(TestIncompleteStatement)

View File

@ -7091,6 +7091,12 @@ private:
// C++17: if (expr1; expr2) // C++17: if (expr1; expr2)
ASSERT_EQUALS("ifx3=y;(", testAst("if (int x=3; y)")); ASSERT_EQUALS("ifx3=y;(", testAst("if (int x=3; y)"));
ASSERT_EQUALS("a( forx0=x;;(", testAst("struct c { void a() const { for (int x=0; x;); } };"));
// TODO: We dont correctly parse ref qualifiers
TODO_ASSERT_EQUALS("a( forx0=x;;(", "a({&", testAst("struct c { void a() & { for (int x=0; x;); } };"));
TODO_ASSERT_EQUALS("a( forx0=x;;(", "a({&&", testAst("struct c { void a() && { for (int x=0; x;); } };"));
} }
void astexpr2() { // limit for large expressions void astexpr2() { // limit for large expressions