Fixed creation of SymbolDatabase for some template code (#7594)

This commit is contained in:
Robert Reif 2016-07-09 09:22:52 +02:00 committed by PKEuS
parent 44a19b527e
commit c1594bedbb
2 changed files with 23 additions and 1 deletions

View File

@ -101,7 +101,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
tok2->next()->link()->strAt(1) == ";") tok2->next()->link()->strAt(1) == ";")
tok = tok2->next()->link()->next(); tok = tok2->next()->link()->next();
// skip variable declaration // skip variable declaration
else if (Token::Match(tok2, "*|&")) else if (Token::Match(tok2, "*|&|>"))
continue; continue;
else else
break; // bail break; // bail

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(localvar46); // ticket #5491 (C++11 style initialization) TEST_CASE(localvar46); // ticket #5491 (C++11 style initialization)
TEST_CASE(localvar47); // ticket #6603 TEST_CASE(localvar47); // ticket #6603
TEST_CASE(localvar48); // ticket #6954 TEST_CASE(localvar48); // ticket #6954
TEST_CASE(localvar49); // ticket #7594
TEST_CASE(localvaralias1); TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639 TEST_CASE(localvaralias3); // ticket #1639
@ -1936,6 +1937,27 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvar49() { // #7594
functionVariableUsage("class A {\n"
" public:\n"
" typedef enum { ID1,ID2,ID3 } Id_t;\n"
" typedef struct {Id_t id; std::string a; } x_t;\n"
" std::vector<x_t> m_vec;\n"
" std::vector<x_t> Get(void);\n"
" void DoSomething();\n"
"};\n"
"std::vector<A::x_t> A::Get(void) {\n"
" return m_vec;\n"
"}\n"
"const std::string Bar() {\n"
" return \"x\";\n"
"}\n"
"void A::DoSomething(void) {\n"
" const std::string x = Bar();\n"
"}");
ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
}
void localvaralias1() { void localvaralias1() {
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"