Fixed #7058 (Tokenizer::simplifyTypedef: wrong simplification of enum constant 'AB::A' if AB is a struct typedef)

This commit is contained in:
Daniel Marjamäki 2015-10-18 04:55:04 +02:00
parent ec87b09d89
commit fe4fac7eb2
2 changed files with 11 additions and 1 deletions

View File

@ -1201,7 +1201,7 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->next(); tok2 = tok2->next();
} }
} }
} else if (tok2->tokAt(-2) && Token::Match(tok2->tokAt(-2), "%type% *|&")) { } else if (Token::Match(tok2->tokAt(-2), "%type% *|&")) {
// Ticket #5868: Don't substitute variable names // Ticket #5868: Don't substitute variable names
} else if (tok2->previous()->str() != ".") { } else if (tok2->previous()->str() != ".") {
simplifyType = true; simplifyType = true;
@ -1264,6 +1264,8 @@ void Tokenizer::simplifyTypedef()
structRemoved = true; structRemoved = true;
typeStart = typeStart->next(); typeStart = typeStart->next();
} }
if (typeStart->str() == "struct" && Token::Match(tok2, "%name% ::"))
typeStart = typeStart->next();
// start substituting at the typedef name by replacing it with the type // start substituting at the typedef name by replacing it with the type
tok2->str(typeStart->str()); tok2->str(typeStart->str());

View File

@ -150,6 +150,7 @@ private:
TEST_CASE(simplifyTypedef111); // ticket #6345 TEST_CASE(simplifyTypedef111); // ticket #6345
TEST_CASE(simplifyTypedef112); // ticket #6048 TEST_CASE(simplifyTypedef112); // ticket #6048
TEST_CASE(simplifyTypedef113); // ticket #7030 TEST_CASE(simplifyTypedef113); // ticket #7030
TEST_CASE(simplifyTypedef114); // ticket #7058 - skip "struct", AB::..
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -2414,6 +2415,13 @@ private:
ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS(expected, tok(code));
} }
void simplifyTypedef114() { // ticket #7058
const char code[] = "typedef struct { enum {A,B}; } AB;\n"
"x=AB::B;";
const char expected[] = "struct AB { } ; x = 1 ;";
ASSERT_EQUALS(expected, tok(code));
}
void simplifyTypedefFunction1() { void simplifyTypedefFunction1() {
{ {
const char code[] = "typedef void (*my_func)();\n" const char code[] = "typedef void (*my_func)();\n"