Fixed #3340 (Internal error. Token::Match called with varid 0... union is causing problems)

This commit is contained in:
Daniel Marjamäki 2011-11-20 08:13:28 +01:00
parent 2a5b4b1842
commit 8c091ff968
2 changed files with 14 additions and 1 deletions

View File

@ -3398,7 +3398,7 @@ void Tokenizer::setVarId()
if (tok->str() == "unsigned") if (tok->str() == "unsigned")
tok = tok->next(); tok = tok->next();
if (Token::Match(tok, "class|struct %type% :|{|;")) if (Token::Match(tok, "class|struct|union %type% :|{|;"))
continue; continue;
if (Token::Match(tok, "using namespace %type% ;")) { if (Token::Match(tok, "using namespace %type% ;")) {

View File

@ -189,6 +189,7 @@ private:
TEST_CASE(varid38); // ticket #3272 (varid for 'FOO class C;') TEST_CASE(varid38); // ticket #3272 (varid for 'FOO class C;')
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(varidFunctionCall1); TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall3);
@ -3016,6 +3017,18 @@ private:
tokenizeDebugListing(code)); tokenizeDebugListing(code));
} }
void varid41() {
const std::string code1("union evt; void f(const evt & event);");
ASSERT_EQUALS("\n\n##file 0\n"
"1: union evt ; void f ( const evt & event@1 ) ;\n",
tokenizeDebugListing(code1));
const std::string code2("struct evt; void f(const evt & event);");
ASSERT_EQUALS("\n\n##file 0\n"
"1: struct evt ; void f ( const evt & event@1 ) ;\n",
tokenizeDebugListing(code2));
}
void varidFunctionCall1() { void varidFunctionCall1() {
const std::string code("void f() {\n" const std::string code("void f() {\n"
" int x;\n" " int x;\n"