Fixed #2452 (syntax error when 'void f(typedef int x)' is used. causes segmentation fault.)
This commit is contained in:
parent
012b07023b
commit
708a75e363
|
@ -856,6 +856,13 @@ void Tokenizer::simplifyTypedef()
|
||||||
else if (tok->str() != "typedef")
|
else if (tok->str() != "typedef")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// check for syntax errors
|
||||||
|
if (tok->previous() && tok->previous()->str() == "(")
|
||||||
|
{
|
||||||
|
syntaxError(tok);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// pull struct, union, enum or class definition out of typedef
|
// pull struct, union, enum or class definition out of typedef
|
||||||
// use typedef name for unnamed struct, union, enum or class
|
// use typedef name for unnamed struct, union, enum or class
|
||||||
if (Token::Match(tok->next(), "const| struct|enum|union|class %type% {") ||
|
if (Token::Match(tok->next(), "const| struct|enum|union|class %type% {") ||
|
||||||
|
|
|
@ -233,6 +233,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef73); // ticket #2412
|
TEST_CASE(simplifyTypedef73); // ticket #2412
|
||||||
TEST_CASE(simplifyTypedef74); // ticket #2414
|
TEST_CASE(simplifyTypedef74); // ticket #2414
|
||||||
TEST_CASE(simplifyTypedef75); // ticket #2426
|
TEST_CASE(simplifyTypedef75); // ticket #2426
|
||||||
|
TEST_CASE(simplifyTypedef76); // ticket #2453
|
||||||
|
|
||||||
TEST_CASE(simplifyTypedefFunction1);
|
TEST_CASE(simplifyTypedefFunction1);
|
||||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||||
|
@ -4795,6 +4796,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef76() // ticket #2453 segmentation fault
|
||||||
|
{
|
||||||
|
const char code[] = "void f1(typedef int x) {}\n";
|
||||||
|
const std::string expected = "void f1 ( typedef int x ) { }";
|
||||||
|
ASSERT_EQUALS(expected, sizeof_(code));
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyTypedefFunction1()
|
void simplifyTypedefFunction1()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue