Merge branch 'master' of github.com:danmar/cppcheck
This commit is contained in:
commit
e332f0c186
|
@ -5807,6 +5807,14 @@ void Tokenizer:: simplifyFunctionPointers()
|
|||
{
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
// #2873 - dont simplify function pointer usage here:
|
||||
// (void)(xy(*p)(0));
|
||||
if (Token::simpleMatch(tok, ") ("))
|
||||
{
|
||||
tok = tok->next()->link();
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for function pointer cast
|
||||
if (Token::Match(tok, "( %type% *| *| ( * ) (") ||
|
||||
Token::Match(tok, "( %type% %type% *| *| ( * ) (") ||
|
||||
|
|
|
@ -284,6 +284,7 @@ private:
|
|||
|
||||
TEST_CASE(functionpointer1);
|
||||
TEST_CASE(functionpointer2);
|
||||
TEST_CASE(functionpointer3);
|
||||
|
||||
TEST_CASE(removeRedundantAssignment);
|
||||
|
||||
|
@ -4846,6 +4847,18 @@ private:
|
|||
ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
|
||||
}
|
||||
|
||||
void functionpointer3()
|
||||
{
|
||||
// Related with ticket #2873
|
||||
const char code[] = "void f() {\n"
|
||||
"(void)(xy(*p)(0);)"
|
||||
"\n}";
|
||||
const char expected[] = " void f(){"
|
||||
"( void)( xy(* p)(0);)"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
|
||||
}
|
||||
|
||||
void removeRedundantAssignment()
|
||||
{
|
||||
ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
|
||||
|
|
Loading…
Reference in New Issue