Merge pull request #786 from prozak/master

- fix for #5749 defect: internal error
This commit is contained in:
amai2012 2016-04-24 22:19:02 +02:00
commit 7a8a6695a4
2 changed files with 38 additions and 8 deletions

View File

@ -1430,9 +1430,19 @@ void Tokenizer::simplifyTypedef()
tok2->insertToken("*");
tok2 = tok2->next();
} else {
tok2->insertToken("(");
tok2 = tok2->next();
Token *tok3 = tok2;
// This is the case of casting operator.
// Name is not available, and () should not be
// inserted
bool castOperator = inOperator && Token::Match(tok2, "%type% (");
Token *tok3;
if (!castOperator) {
tok2->insertToken("(");
tok2 = tok2->next();
tok3 = tok2;
}
const Token *tok4 = namespaceStart;
@ -1447,12 +1457,15 @@ void Tokenizer::simplifyTypedef()
tok2->insertToken("*");
tok2 = tok2->next();
// skip over name
tok2 = tok2->next();
if (!castOperator) {
// skip over name
tok2 = tok2->next();
tok2->insertToken(")");
tok2 = tok2->next();
Token::createMutualLinks(tok2, tok3);
tok2->insertToken(")");
tok2 = tok2->next();
Token::createMutualLinks(tok2, tok3);
}
}
} else if (typeOf) {
tok2 = copyTokens(tok2, argStart, argEnd);

View File

@ -151,6 +151,7 @@ private:
TEST_CASE(simplifyTypedef115); // ticket #6998
TEST_CASE(simplifyTypedef116); // ticket #5624
TEST_CASE(simplifyTypedef117); // ticket #6507
TEST_CASE(simplifyTypedef118); // ticket #5749
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -2354,6 +2355,22 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef118() { // #5749
const char code[] = "struct ClassyClass {\n"
"int id;\n"
"typedef int (ClassyClass::*funky_type);\n"
"operator funky_type() {\n"
"return &ClassyClass::id;\n"
"}}";
const char expected[] = "struct ClassyClass { "
"int id ; "
"operatorintClassyClass::* ( ) { "
"return & ClassyClass :: id ; "
"} }";
ASSERT_EQUALS(expected, tok(code, false));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"