Fixed #3316 (Cppcheck reporting internal errors - code compiles cleanly)

This commit is contained in:
Daniel Marjamäki 2011-11-20 16:22:21 +01:00
parent a32b05197d
commit 097637a66c
2 changed files with 28 additions and 4 deletions

View File

@ -3409,12 +3409,17 @@ void Tokenizer::setVarId()
if (tok->str() == "virtual") if (tok->str() == "virtual")
continue; continue;
if (tok->str() == "unsigned")
tok = tok->next();
if (Token::Match(tok, "class|struct|union %type% :|{|;")) if (Token::Match(tok, "class|struct|union %type% :|{|;"))
continue; continue;
while (Token::Match(tok, "public:|private:|protected:"))
tok = tok->next();
if (!tok)
break;
if (tok->str() == "unsigned")
tok = tok->next();
if (Token::Match(tok, "using namespace %type% ;")) { if (Token::Match(tok, "using namespace %type% ;")) {
tok = tok->next(); tok = tok->next();
continue; continue;
@ -3426,12 +3431,15 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "else|return|typedef|delete|sizeof")) if (Token::Match(tok, "else|return|typedef|delete|sizeof"))
continue; continue;
while (Token::Match(tok, "const|static|extern|public:|private:|protected:|;|mutable")) while (Token::Match(tok, "const|static|extern|;|mutable"))
tok = tok->next(); tok = tok->next();
if (tok && tok->str() == "friend") if (tok && tok->str() == "friend")
continue; continue;
if (Token::Match(tok, "struct %type%"))
tok = tok->next();
// skip global namespace prefix // skip global namespace prefix
if (Token::simpleMatch(tok, "::")) if (Token::simpleMatch(tok, "::"))
tok = tok->next(); tok = tok->next();

View File

@ -190,6 +190,7 @@ private:
TEST_CASE(varid39); // ticket #3279 (varid for 'FOO::BAR const') TEST_CASE(varid39); // ticket #3279 (varid for 'FOO::BAR const')
TEST_CASE(varid40); // ticket #3279 TEST_CASE(varid40); // ticket #3279
TEST_CASE(varid41); // ticket #3340 (varid for union type) TEST_CASE(varid41); // ticket #3340 (varid for union type)
TEST_CASE(varid42); // ticket #3316 (varid for array)
TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall3);
@ -3030,6 +3031,21 @@ private:
tokenizeDebugListing(code2)); tokenizeDebugListing(code2));
} }
void varid42() {
const std::string code("namespace fruit { struct banana {}; };\n"
"class Fred {\n"
"public:\n"
" struct fruit::banana Bananas[25];\n"
"};");
ASSERT_EQUALS("\n\n##file 0\n"
"1: namespace fruit { struct banana { } ; } ;\n"
"2: class Fred {\n"
"3: public:\n"
"4: struct fruit :: banana Bananas@1 [ 25 ] ;\n"
"5: } ;\n",
tokenizeDebugListing(code));
}
void varidFunctionCall1() { void varidFunctionCall1() {
const std::string code("void f() {\n" const std::string code("void f() {\n"
" int x;\n" " int x;\n"