diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c954ca0eba7..7b173e7174a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1040,6 +1040,10 @@ namespace { return mEndToken; } + Token* nameToken() const { + return mNameToken; + } + private: static bool isCast(const Token* tok) { if (Token::Match(tok, "( %name% ) (|%name%|%num%")) @@ -1145,6 +1149,7 @@ void Tokenizer::simplifyTypedef() typedefInfo.lineNumber = typedefToken->linenr(); typedefInfo.column = typedefToken->column(); typedefInfo.used = t.second.isUsed(); + typedefInfo.isFunctionPointer = Token::Match(t.second.nameToken(), "%name% ) ("); mTypedefInfo.push_back(std::move(typedefInfo)); t.second.removeDeclaration(); @@ -1645,6 +1650,7 @@ void Tokenizer::simplifyTypedefCpp() typedefInfo.lineNumber = typeName->linenr(); typedefInfo.column = typeName->column(); typedefInfo.used = false; + typedefInfo.isFunctionPointer = Token::Match(typeName, "%name% ) ("); mTypedefInfo.push_back(std::move(typedefInfo)); while (!done) { @@ -6194,6 +6200,10 @@ std::string Tokenizer::dumpTypedefInfo() const outs += std::to_string(typedefInfo.used?1:0); outs += "\""; + outs += " isFunctionPointer=\""; + outs += std::to_string(typedefInfo.isFunctionPointer); + outs += "\""; + outs += "/>"; outs += '\n'; } diff --git a/lib/tokenize.h b/lib/tokenize.h index cb66342797e..ea4ddffcffa 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -667,6 +667,7 @@ class CPPCHECKLIB Tokenizer { int lineNumber; int column; bool used; + bool isFunctionPointer; }; std::vector mTypedefInfo; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index cff9c763ab0..f606bed734b 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -243,6 +243,8 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedefOriginalName); TEST_CASE(typedefInfo1); + + TEST_CASE(typedefInfo2); } #define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) @@ -4402,10 +4404,23 @@ class TestSimplifyTypedef : public TestFixture { void typedefInfo1() { const std::string xml = dumpTypedefInfo("typedef int A;\nA x;"); ASSERT_EQUALS(" \n" - " \n" + " \n" " \n", xml); } + + void typedefInfo2() { + const std::string xml = dumpTypedefInfo("typedef signed short int16_t;\n" + "typedef void ( *fp16 )( int16_t n );\n" + "void R_11_1 ( void ){\n" + " typedef fp16 ( *pfp16 ) ( void );\n" + "}\n"); + ASSERT_EQUALS(" \n" + " \n" + " \n" + " \n" + " \n",xml); + } }; REGISTER_TEST(TestSimplifyTypedef)