Fixed #2035 (Enum 'qboolean' hides typedef with same name)

This commit is contained in:
Robert Reif 2010-09-08 06:45:57 +02:00 committed by Daniel Marjamäki
parent 86a08b9f0e
commit 2fc2859b68
2 changed files with 35 additions and 3 deletions

View File

@ -783,6 +783,17 @@ void Tokenizer::simplifyTypedef()
tok->deleteThis(); tok->deleteThis();
tok = tok3; tok = tok3;
} }
/** @todo add support for struct and union */
if (Token::Match(tok, "typedef enum %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
{
tok->deleteThis();
tok->deleteThis();
tok->deleteThis();
tok->deleteThis();
continue;
}
Token *typeName; Token *typeName;
std::list<std::string> pointers; std::list<std::string> pointers;
Token *typeStart = 0; Token *typeStart = 0;
@ -7001,7 +7012,8 @@ void Tokenizer::simplifyEnum()
{ {
// Don't replace this enum if it's preceded by "::" // Don't replace this enum if it's preceded by "::"
} }
else if (tok2->next() && tok2->next()->isName()) else if (tok2->next() &&
(tok2->next()->isName() || tok2->next()->str() == "("))
{ {
simplify = true; simplify = true;
hasClass = false; hasClass = false;

View File

@ -215,6 +215,7 @@ private:
TEST_CASE(simplifyTypedef57); // ticket #1846 TEST_CASE(simplifyTypedef57); // ticket #1846
TEST_CASE(simplifyTypedef58); // ticket #1963 TEST_CASE(simplifyTypedef58); // ticket #1963
TEST_CASE(simplifyTypedef59); // ticket #2011 TEST_CASE(simplifyTypedef59); // ticket #2011
TEST_CASE(simplifyTypedef60); // ticket #2035
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -757,7 +758,7 @@ private:
// Simplify 'sizeof'.. // Simplify 'sizeof'..
std::string sizeof_(const char code[]) std::string sizeof_(const char code[], bool simplify = true)
{ {
// tokenize.. // tokenize..
Settings settings; Settings settings;
@ -766,6 +767,7 @@ private:
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
if (simplify)
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
std::ostringstream ostr; std::ostringstream ostr;
@ -4409,6 +4411,24 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef60() // ticket #2035
{
const char code[] = "typedef enum {qfalse, qtrue} qboolean;\n"
"typedef qboolean (*localEntitiyAddFunc_t) (struct le_s * le, entity_t * ent);\n"
"void f()\n"
"{\n"
" qboolean b;\n"
" localEntitiyAddFunc_t f;\n"
"}\n";
// The expected result..
const std::string expected("; ; ; void f ( ) { int b ; int * f ; }");
ASSERT_EQUALS(expected, sizeof_(code, false));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {