Fixed #6424 (false negative: Use of 'class Ns::C' silence Cppcheck)
This commit is contained in:
parent
e7a95e68ac
commit
3b8540fdc0
|
@ -74,6 +74,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
else if (Token::Match(tok2->next(), "(|{") &&
|
||||
tok2->next()->link()->strAt(1) == ";")
|
||||
tok = tok2->next()->link()->next();
|
||||
// skip variable declaration
|
||||
else if (Token::Match(tok2, "*|&"))
|
||||
continue;
|
||||
else
|
||||
break; // bail
|
||||
continue;
|
||||
|
@ -2768,7 +2771,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
|
|||
// the start of the type tokens does not include the above modifiers
|
||||
const Token *typestart = tok;
|
||||
|
||||
if (Token::Match(tok, "struct|union")) {
|
||||
if (Token::Match(tok, "class|struct|union")) {
|
||||
tok = tok->next();
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ private:
|
|||
TEST_CASE(symboldatabase46); // #6171 (anonymous namespace)
|
||||
TEST_CASE(symboldatabase47); // #6308
|
||||
TEST_CASE(symboldatabase48); // #6417
|
||||
TEST_CASE(symboldatabase49); // #6424
|
||||
|
||||
TEST_CASE(isImplicitlyVirtual);
|
||||
|
||||
|
@ -2078,6 +2079,18 @@ private:
|
|||
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 4 && f->function()->token->linenr() == 8);
|
||||
}
|
||||
|
||||
void symboldatabase49() { // #6424
|
||||
GET_SYMBOL_DB("namespace Ns { class C; }\n"
|
||||
"void f1() { char *p; *p = 0; }\n"
|
||||
"class Ns::C* p;\n"
|
||||
"void f2() { char *p; *p = 0; }\n");
|
||||
ASSERT(db != nullptr);
|
||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "p ; void f2");
|
||||
ASSERT_EQUALS(true, db && f && f->variable());
|
||||
f = Token::findsimplematch(tokenizer.tokens(), "f2");
|
||||
ASSERT_EQUALS(true, db && f && f->function());
|
||||
}
|
||||
|
||||
void isImplicitlyVirtual() {
|
||||
{
|
||||
GET_SYMBOL_DB("class Base {\n"
|
||||
|
|
|
@ -69,6 +69,7 @@ private:
|
|||
TEST_CASE(uninitvar2_malloc); // malloc returns uninitialized data
|
||||
TEST_CASE(uninitvar7); // ticket #5971
|
||||
TEST_CASE(uninitvar8); // ticket #6230
|
||||
TEST_CASE(uninitvar9); // ticket #6424
|
||||
|
||||
TEST_CASE(syntax_error); // Ticket #5073
|
||||
|
||||
|
@ -2710,6 +2711,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar9() { // 6424
|
||||
const char code[] = "namespace Ns { class C; }\n"
|
||||
"void f1() { char *p; *p = 0; }\n"
|
||||
"class Ns::C* p;\n"
|
||||
"void f2() { char *p; *p = 0; }";
|
||||
checkUninitVar2(code, "test.cpp");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: p\n"
|
||||
"[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
}
|
||||
|
||||
// Handling of function calls
|
||||
void uninitvar2_func() {
|
||||
// non-pointer variable
|
||||
|
|
Loading…
Reference in New Issue