Fixed #4585 (false positive, Variable 'b' is assigned a value that is never used when using+loop)

This commit is contained in:
Robert Reif 2013-02-14 06:31:41 +01:00 committed by Daniel Marjamäki
parent 5de26bfeb9
commit a1da067b88
2 changed files with 27 additions and 2 deletions

View File

@ -192,7 +192,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
// using namespace
else if (Token::Match(tok, "using namespace %type% ;|::")) {
else if (Token::Match(tok, "using namespace ::| %type% ;|::")) {
Scope::UsingInfo using_info;
using_info.start = tok; // save location
@ -200,7 +200,15 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
scope->usingList.push_back(using_info);
tok = tok->tokAt(3);
// check for global namespace
if (tok->strAt(2) == "::")
tok = tok->tokAt(4);
else
tok = tok->tokAt(3);
// skip over qualification
while (tok && Token::Match(tok, "%type% ::"))
tok = tok->tokAt(2);
}
// unnamed struct and union

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(localvarNULL); // #4203 - Setting NULL value is not redundant - it is safe
TEST_CASE(crash1);
TEST_CASE(usingNamespace); // #4585
}
void checkStructMemberUsage(const char code[]) {
@ -3570,6 +3571,22 @@ private:
"}\n"
"SAL_WNODEPRECATED_DECLARATIONS_POP"); // #4033
}
void usingNamespace() {
functionVariableUsage("int foo() {\n"
" using namespace ::com::sun::star::i18n;\n"
" bool b = false;\n"
" int j = 0;\n"
" for (int i = 0; i < 3; i++) {\n"
" if (!b) {\n"
" j = 3;\n"
" b = true;\n"
" }\n"
" }\n"
" return j;\n"
"}\n"); // #4585
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestUnusedVar)