From 7d6c5875806858d7e8a8f82b0570106f7bbe7a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 4 Aug 2016 19:10:08 +0200 Subject: [PATCH] Fixed #6113 (Tokenizer::simplifyFunctionPointer: wrong simplification of usage 'return (*f)();') --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0c08176e2..650420b87 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5b1aa8bab..0294f5658 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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));