remove casts: Added test case to ensure that function declarations are not reduced
This commit is contained in:
parent
8187504cbb
commit
7ccb6217bf
|
@ -1308,7 +1308,7 @@ bool Tokenizer::simplifyCasts()
|
|||
bool ret = false;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok->next(), "( %type% * )"))
|
||||
if (!tok->isName() && Token::Match(tok->next(), "( %type% * )"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->deleteNext();
|
||||
|
|
|
@ -40,6 +40,8 @@ private:
|
|||
{
|
||||
TEST_CASE(longtok);
|
||||
|
||||
TEST_CASE(removeCast1);
|
||||
|
||||
TEST_CASE(inlineasm);
|
||||
|
||||
TEST_CASE(dupfuncname);
|
||||
|
@ -76,8 +78,7 @@ private:
|
|||
|
||||
TEST_CASE(simplify_function_parameters);
|
||||
|
||||
TEST_CASE(reduce_redundant_paranthesis1); // Ticket #61
|
||||
TEST_CASE(reduce_redundant_paranthesis2); // Ticket #61
|
||||
TEST_CASE(reduce_redundant_paranthesis); // Ticket #61
|
||||
|
||||
TEST_CASE(sizeof1);
|
||||
TEST_CASE(sizeof2);
|
||||
|
@ -144,6 +145,26 @@ private:
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Dont remove "(int *)"..
|
||||
void removeCast1()
|
||||
{
|
||||
const char code[] = "int *f(int *);";
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
tokenizer.simplifyCasts();
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(std::string(" int * f ( int * ) ;"), ostr.str());
|
||||
}
|
||||
|
||||
|
||||
void inlineasm()
|
||||
{
|
||||
const char filedata[] = "void foo()\n"
|
||||
|
@ -810,7 +831,7 @@ private:
|
|||
|
||||
|
||||
// Simplify "((..))" into "(..)"
|
||||
void reduce_redundant_paranthesis1()
|
||||
void reduce_redundant_paranthesis()
|
||||
{
|
||||
const char code[] = "void foo()\n"
|
||||
"{\n"
|
||||
|
@ -830,28 +851,6 @@ private:
|
|||
ASSERT_EQUALS(std::string(" void foo ( ) { free ( p ) ; }"), ostr.str());
|
||||
}
|
||||
|
||||
// Simplify "((..))" into "(..)"
|
||||
void reduce_redundant_paranthesis2()
|
||||
{
|
||||
const char code[] = "class A\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" A();\n"
|
||||
" int *p(int *);\n"
|
||||
"}";
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(std::string(" class A { public: A ( ) ; int * p ( int * ) ; }"), ostr.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue