Merge pull request #335 from simartin/ticket_5907

Ticket #5907: Properly handle extern declarations in Tokenizer::simplifyVarDecl
This commit is contained in:
Daniel Marjamäki 2014-06-08 15:59:23 +02:00
commit 228d67cf05
2 changed files with 10 additions and 2 deletions

View File

@ -5257,7 +5257,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
continue;
Token *type0 = tok;
if (!Token::Match(type0, "::| %type%"))
if (!Token::Match(type0, "::|extern| %type%"))
continue;
if (Token::Match(type0, "else|return|public:|protected:|private:"))
continue;
@ -5267,7 +5267,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
Token *tok2 = type0;
unsigned int typelen = 1;
if (tok2->str() == "::") {
if (Token::Match(tok2, "::|extern")) {
tok2 = tok2->next();
typelen++;
}

View File

@ -412,6 +412,7 @@ private:
TEST_CASE(vardecl23); // #4276 - segmentation fault
TEST_CASE(vardecl24); // #4187 - variable declaration within lambda function
TEST_CASE(vardecl25); // #4799 - segmentation fault
TEST_CASE(vardecl26); // #5907 - incorrect handling of extern declarations
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_template_1);
@ -6355,6 +6356,13 @@ private:
"}");
}
void vardecl26() { // #5907
const char code[] = "extern int *new, obj, player;";
const char expected[] = "extern int * new ; extern int obj ; extern int player ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Unspecified, "test.c"));
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
}
void volatile_variables() {
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"