Fixed #6113 (Tokenizer::simplifyFunctionPointer: wrong simplification of usage 'return (*f)();')
This commit is contained in:
parent
084fcc936c
commit
7d6c587580
|
@ -5207,6 +5207,9 @@ void Tokenizer::simplifyFunctionPointers()
|
|||
else if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|,|(|public:|protected:|private:"))
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "delete|else|return|throw|typedef"))
|
||||
continue;
|
||||
|
||||
while (Token::Match(tok, "%type%|:: %type%|::"))
|
||||
tok = tok->next();
|
||||
|
||||
|
|
|
@ -308,6 +308,7 @@ private:
|
|||
TEST_CASE(functionpointer6);
|
||||
TEST_CASE(functionpointer7);
|
||||
TEST_CASE(functionpointer8); // #7410 - throw
|
||||
TEST_CASE(functionpointer9); // #6113 - function call with function pointer
|
||||
|
||||
TEST_CASE(removeRedundantAssignment);
|
||||
|
||||
|
@ -4696,6 +4697,20 @@ private:
|
|||
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false));
|
||||
}
|
||||
|
||||
void functionpointer9() { // function call with function pointer
|
||||
const char code1[] = "int f() { (*f)(); }";
|
||||
const char expected1[] = "1: int f ( ) { ( * f ) ( ) ; }\n";
|
||||
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false));
|
||||
|
||||
const char code2[] = "int f() { return (*f)(); }";
|
||||
const char expected2[] = "1: int f ( ) { return ( * f ) ( ) ; }\n";
|
||||
ASSERT_EQUALS(expected2, tokenizeDebugListing(code2, false));
|
||||
|
||||
const char code3[] = "int f() { throw (*f)(); }";
|
||||
const char expected3[] = "1: int f ( ) { throw ( * f ) ( ) ; }\n";
|
||||
ASSERT_EQUALS(expected3, tokenizeDebugListing(code3, false));
|
||||
}
|
||||
|
||||
void removeRedundantAssignment() {
|
||||
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
|
||||
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));
|
||||
|
|
Loading…
Reference in New Issue