fix #2587 (Spurious warning about struct hiding typedef)

This commit is contained in:
Robert Reif 2011-02-19 14:18:37 -05:00
parent f9b1505115
commit 77fe9858e2
2 changed files with 39 additions and 11 deletions

View File

@ -837,6 +837,15 @@ static Token *splitDefinitionFromTypedef(Token *tok)
tok1->insertToken(";");
tok1 = tok1->next();
if (tok1->next()->str() == ";" && tok1 && tok1->previous()->str() == "}")
{
tok->deleteThis();
tok1->deleteThis();
return NULL;
}
else
{
tok1->insertToken("typedef");
tok1 = tok1->next();
Token * tok3 = tok1;
@ -850,6 +859,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
tok1->insertToken(name.c_str());
tok->deleteThis();
tok = tok3;
}
return tok;
}

View File

@ -237,6 +237,7 @@ private:
TEST_CASE(simplifyTypedef77); // ticket #2554
TEST_CASE(simplifyTypedef78); // ticket #2568
TEST_CASE(simplifyTypedef79); // ticket #2348
TEST_CASE(simplifyTypedef80); // ticket #2587
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4876,6 +4877,23 @@ private:
ASSERT_EQUALS(expected, sizeof_(code));
}
void simplifyTypedef80() // ticket #2587
{
const char code[] = "typedef struct s { };\n"
"void f() {\n"
" sizeof(struct s);\n"
"};\n";
const std::string expected = "struct s { } ; "
"void f ( ) { "
"sizeof ( struct s ) ; "
"} ;";
ASSERT_EQUALS(expected, sizeof_(code));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{