Fix #9446 (Syntax error on valid C++ code) (#2316)

This commit is contained in:
IOBYTE 2019-11-01 04:11:29 -04:00 committed by amai2012
parent e9bc62d5b4
commit 3f0ef01154
2 changed files with 21 additions and 3 deletions

View File

@ -1446,8 +1446,11 @@ void Tokenizer::simplifyTypedef()
tok2->insertToken("&");
tok2 = tok2->next();
bool hasName = false;
// skip over name
if (tok2->next() && tok2->next()->str() != ")") {
if (tok2->next() && tok2->next()->str() != ")" && tok2->next()->str() != "," &&
tok2->next()->str() != ">") {
hasName = true;
if (tok2->next()->str() != "(")
tok2 = tok2->next();
@ -1458,12 +1461,13 @@ void Tokenizer::simplifyTypedef()
// check for array
if (tok2 && tok2->next() && tok2->next()->str() == "[")
tok2 = tok2->next()->link();
} else {
// syntax error
}
tok2->insertToken(")");
Token::createMutualLinks(tok2->next(), tok3);
if (!hasName)
tok2 = tok2->next();
} else if (ptrMember) {
if (Token::simpleMatch(tok2, "* (")) {
tok2->insertToken("*");

View File

@ -165,6 +165,7 @@ private:
TEST_CASE(simplifyTypedef127); // ticket #8878
TEST_CASE(simplifyTypedef128); // ticket #9053
TEST_CASE(simplifyTypedef129);
TEST_CASE(simplifyTypedef130); // ticket #9446
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -2602,6 +2603,19 @@ private:
}
}
void simplifyTypedef130() { // #9446
const char code[] = "template <class, class> void a() {\n"
" typedef int(*b)[10];\n"
" a<b, b>();\n"
"}";
const char exp [] = "template < class , class > void a ( ) { "
"a < int ( * ) [ 10 ] , int ( * ) [ 10 ] > ( ) ; "
"}";
ASSERT_EQUALS(exp, tok(code, false));
}
void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"