Hello,
I was getting the .dump file and notice a couple of problems that I hope you can help me with with a workaround:
Token not recognized as function: I was parsing for function call and cppcheck doesn't recognize a few tokens as functions. I've included the required include paths with -I and even when outputting the .dump file, the function definition is in the symbol database as well (although the definition is in another header file). Is there a proper way to get this function, since it's in the symbol database?
Token is a typedef but not simplified: cppcheck does the typedef simplification beforehand, but when I output the dump file, it wasn't simplified. And again, the typedef seems to be in the symbol database (under < typdef-info > at the end of the .dump file). Is there a proper way to get this typedef info via symbol database?
Thank you very much for the help!
Last edit: Charles-the-intern 2022-10-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@danielmarjamaki
No, I'm looking at the tokenlist section... but for this problem seems like I found out the reason why:
typedeffooooofooinlinefoof(){returnfoo();}
I notices, in the .dump file, that because function is inline, the return type (as part of function interface) is foo; even though inside the function definition it's still returning the original, actual type fooooo
Does cppcheck deliberate do this?
Last edit: Charles-the-intern 2022-10-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding the typedef issue, a big reason why it wasn't working in my case is because of the setup where we have a few #includes inside namespace A {} AND extensive use of a precompiled header that specifies using namespace A for all translation units that include this precompiled header. The precompiled header, along with its recursively included headers, are all included correctly, but seems like these #includes being inside namespace causes the issue.
... perhaps this is also the reason why some tokens are not recognized as function properly
Last edit: Charles-the-intern 2022-10-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe you have found some other bug. Can you create a small example code? It should not matter that a #include is inside a namespace the preprocessor does not care about that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please find below the attachments as an example. There're 2 issues but they're caused by the same reason: typdef is not simplified (different from above example) and token is not recognized as function.
I noticed that if you don't do the using namespace and instead explicitly use the scope resolution ::, everything works.
main.h
namespacens{#include"header.h"}
header.h
typedefintfoo;foofunction(){foof=0;returnf;}
main.cpp
#include"main.h"usingnamespacens;intmain(){// ns::foo f = ns::function();foof=function();return0;}
.dump
<?xml version="1.0"?><dumps><platformname="win64"char_bit="8"short_bit="16"int_bit="32"long_bit="32"long_long_bit="64"pointer_bit="64"/><rawtokens><fileindex="0"name="main.cpp"/><fileindex="1"name="main.h"/><fileindex="2"name="header.h"/><tokfileIndex="0"linenr="2"column="1"str="#"/><tokfileIndex="0"linenr="2"column="2"str="include"/><tokfileIndex="0"linenr="2"column="10"str=""main.h""/><tokfileIndex="0"linenr="4"column="1"str="using"/><tokfileIndex="0"linenr="4"column="7"str="namespace"/><tokfileIndex="0"linenr="4"column="17"str="ns"/><tokfileIndex="0"linenr="4"column="19"str=";"/><tokfileIndex="0"linenr="6"column="1"str="int"/><tokfileIndex="0"linenr="6"column="5"str="main"/><tokfileIndex="0"linenr="6"column="9"str="("/><tokfileIndex="0"linenr="6"column="10"str=")"/><tokfileIndex="0"linenr="6"column="12"str="{"/><tokfileIndex="0"linenr="7"column="2"str="// ns::foo f = ns::function();"/><tokfileIndex="0"linenr="8"column="2"str="foo"/><tokfileIndex="0"linenr="8"column="6"str="f"/><tokfileIndex="0"linenr="8"column="8"str="="/><tokfileIndex="0"linenr="8"column="10"str="function"/><tokfileIndex="0"linenr="8"column="18"str="("/><tokfileIndex="0"linenr="8"column="19"str=")"/><tokfileIndex="0"linenr="8"column="20"str=";"/><tokfileIndex="0"linenr="10"column="2"str="return"/><tokfileIndex="0"linenr="10"column="9"str="0"/><tokfileIndex="0"linenr="10"column="10"str=";"/><tokfileIndex="0"linenr="11"column="1"str="}"/></rawtokens><suppressions></suppressions><dumpcfg=""><standards><cversion="c11"/><cppversion="c++17"/></standards><directivelist><directivefile="main.cpp"linenr="2"str="#include "main.h""/><directivefile="main.h"linenr="3"str="#include "header.h""/></directivelist><tokenlist><tokenid="000001C49EC851C0"file="main.h"linenr="2"column="1"str="namespace"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49EC85640"file="main.h"linenr="2"column="11"str="ns"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49EC856A0"file="main.h"linenr="2"column="14"str="{"scope="000001C49E961F40"link="000001C49E9202A0"/><tokenid="000001C49E91F520"file="header.h"linenr="4"column="1"str="int"scope="000001C49E961F40"type="name"/><tokenid="000001C49E91F640"file="header.h"linenr="4"column="5"str="function"scope="000001C49E961F40"type="name"function="000001C49E91B6E0"/><tokenid="000001C49E91F040"file="header.h"linenr="4"column="13"str="("scope="000001C49E961F40"link="000001C49E91F7C0"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91F7C0"file="header.h"linenr="4"column="14"str=")"scope="000001C49E961F40"link="000001C49E91F040"/><tokenid="000001C49E9201E0"file="header.h"linenr="4"column="16"str="{"scope="000001C49E962080"link="000001C49E91F1C0"/><tokenid="000001C49E91EDA0"file="header.h"linenr="5"column="2"str="int"scope="000001C49E962080"type="name"/><tokenid="000001C49E91F820"file="header.h"linenr="5"column="6"str="f"scope="000001C49E962080"type="name"varId="1"exprId="1"variable="000001C49EC7FEE0"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91F0A0"file="header.h"linenr="5"column="8"str=";"scope="000001C49E962080"isSplittedVarDeclEq="true"/><tokenid="000001C49E91F2E0"file="header.h"linenr="5"column="6"str="f"scope="000001C49E962080"type="name"varId="1"exprId="1"variable="000001C49EC7FEE0"astParent="000001C49E920240"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E920240"file="header.h"linenr="5"column="8"str="="scope="000001C49E962080"type="op"isAssignmentOp="true"exprId="3"values="000001C49E91EA10"astOperand1="000001C49E91F2E0"astOperand2="000001C49E91F5E0"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91F5E0"file="header.h"linenr="5"column="10"str="0"scope="000001C49E962080"type="number"isInt="true"values="000001C49E91E5B0"astParent="000001C49E920240"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E920120"file="header.h"linenr="5"column="11"str=";"scope="000001C49E962080"/><tokenid="000001C49E91F100"file="header.h"linenr="6"column="2"str="return"scope="000001C49E962080"type="name"astOperand1="000001C49E920300"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E920300"file="header.h"linenr="6"column="9"str="f"scope="000001C49E962080"type="name"varId="1"exprId="1"variable="000001C49EC7FEE0"values="000001C49E91EAF0"astParent="000001C49E91F100"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91FA00"file="header.h"linenr="6"column="10"str=";"scope="000001C49E962080"/><tokenid="000001C49E91F1C0"file="header.h"linenr="7"column="1"str="}"scope="000001C49E962080"link="000001C49E9201E0"/><tokenid="000001C49E9202A0"file="main.h"linenr="4"column="1"str="}"scope="000001C49E961F40"link="000001C49EC856A0"/><tokenid="000001C49E91F940"file="main.cpp"linenr="4"column="1"str="using"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49E91FA60"file="main.cpp"linenr="4"column="7"str="namespace"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49E91EF80"file="main.cpp"linenr="4"column="17"str="ns"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49E91FFA0"file="main.cpp"linenr="4"column="19"str=";"scope="000001C49ECB4EA0"/><tokenid="000001C49E91FAC0"file="main.cpp"linenr="6"column="1"str="int"scope="000001C49ECB4EA0"type="name"/><tokenid="000001C49E91FE20"file="main.cpp"linenr="6"column="5"str="main"scope="000001C49ECB4EA0"type="name"function="000001C49E91C540"/><tokenid="000001C49E920360"file="main.cpp"linenr="6"column="9"str="("scope="000001C49ECB4EA0"link="000001C49E91F400"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91F400"file="main.cpp"linenr="6"column="10"str=")"scope="000001C49ECB4EA0"link="000001C49E920360"/><tokenid="000001C49E91FB80"file="main.cpp"linenr="6"column="12"str="{"scope="000001C49E9621C0"link="000001C49E920420"/><tokenid="000001C49E91F6A0"file="main.cpp"linenr="8"column="2"str="foo"scope="000001C49E9621C0"type="name"/><tokenid="000001C49E91F580"file="main.cpp"linenr="8"column="6"str="f"scope="000001C49E9621C0"type="name"varId="2"exprId="2"variable="000001C49EC7F2A0"/><tokenid="000001C49E91F280"file="main.cpp"linenr="8"column="8"str=";"scope="000001C49E9621C0"isSplittedVarDeclEq="true"/><tokenid="000001C49E91FDC0"file="main.cpp"linenr="8"column="6"str="f"scope="000001C49E9621C0"type="name"varId="2"exprId="2"variable="000001C49EC7F2A0"astParent="000001C49E91ED40"/><tokenid="000001C49E91ED40"file="main.cpp"linenr="8"column="8"str="="scope="000001C49E9621C0"type="op"isAssignmentOp="true"exprId="4"astOperand1="000001C49E91FDC0"astOperand2="000001C49E91F700"/><tokenid="000001C49E9200C0"file="main.cpp"linenr="8"column="10"str="function"scope="000001C49E9621C0"type="name"astParent="000001C49E91F700"/><tokenid="000001C49E91F700"file="main.cpp"linenr="8"column="18"str="("scope="000001C49E9621C0"link="000001C49E920180"exprId="5"astParent="000001C49E91ED40"astOperand1="000001C49E9200C0"/><tokenid="000001C49E920180"file="main.cpp"linenr="8"column="19"str=")"scope="000001C49E9621C0"link="000001C49E91F700"/><tokenid="000001C49E91F880"file="main.cpp"linenr="8"column="20"str=";"scope="000001C49E9621C0"/><tokenid="000001C49E91F8E0"file="main.cpp"linenr="10"column="2"str="return"scope="000001C49E9621C0"type="name"astOperand1="000001C49E91FEE0"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E91FEE0"file="main.cpp"linenr="10"column="9"str="0"scope="000001C49E9621C0"type="number"isInt="true"values="000001C49E91EA30"astParent="000001C49E91F8E0"valueType-type="int"valueType-sign="signed"valueType-reference="None"/><tokenid="000001C49E9203C0"file="main.cpp"linenr="10"column="10"str=";"scope="000001C49E9621C0"/><tokenid="000001C49E920420"file="main.cpp"linenr="11"column="1"str="}"scope="000001C49E9621C0"link="000001C49E91FB80"/></tokenlist><scopes><scopeid="000001C49ECB4EA0"type="Global"><functionList><functionid="000001C49E91C540"token="000001C49E91FE20"tokenDef="000001C49E91FE20"name="main"type="Function"access="Public"/></functionList></scope><scopeid="000001C49E961F40"type="Namespace"className="ns"bodyStart="000001C49EC856A0"bodyEnd="000001C49E9202A0"nestedIn="000001C49ECB4EA0"><functionList><functionid="000001C49E91B6E0"token="000001C49E91F640"tokenDef="000001C49E91F640"name="function"type="Function"access="Public"/></functionList></scope><scopeid="000001C49E962080"type="Function"className="function"bodyStart="000001C49E9201E0"bodyEnd="000001C49E91F1C0"nestedIn="000001C49E961F40"function="000001C49E91B6E0"><varlist><varid="000001C49EC7FEE0"/></varlist></scope><scopeid="000001C49E9621C0"type="Function"className="main"bodyStart="000001C49E91FB80"bodyEnd="000001C49E920420"nestedIn="000001C49ECB4EA0"function="000001C49E91C540"><varlist><varid="000001C49EC7F2A0"/></varlist></scope></scopes><variables><varid="000001C49EC7F2A0"nameToken="000001C49E91F580"typeStartToken="000001C49E91F6A0"typeEndToken="000001C49E91F6A0"access="Local"scope="000001C49E9621C0"constness="0"isArray="false"isClass="true"isConst="false"isExtern="false"isPointer="false"isReference="false"isStatic="false"isVolatile="false"/><varid="000001C49EC7FEE0"nameToken="000001C49E91F820"typeStartToken="000001C49E91EDA0"typeEndToken="000001C49E91EDA0"access="Local"scope="000001C49E962080"constness="0"isArray="false"isClass="false"isConst="false"isExtern="false"isPointer="false"isReference="false"isStatic="false"isVolatile="false"/></variables><valueflow><valuesid="000001C49E91EA10"><valueintvalue="0"bound="Point"known="true"path="0"/></values><valuesid="000001C49E91E5B0"><valueintvalue="0"bound="Point"known="true"path="0"/></values><valuesid="000001C49E91EAF0"><valueintvalue="0"bound="Point"known="true"path="0"/></values><valuesid="000001C49E91EA30"><valueintvalue="0"bound="Point"known="true"path="0"/></values></valueflow><typedef-info><infoname="foo"file="header.h"line="2"column="13"used="1"/></typedef-info></dump></dumps>
Thank you very much for logging these tickets! I know these issues probably won't get fixed before next release, still I look forward to the next version!
Hello,
I was getting the .dump file and notice a couple of problems that I hope you can help me with with a workaround:
Token not recognized as function: I was parsing for function call and cppcheck doesn't recognize a few tokens as functions. I've included the required include paths with -I and even when outputting the .dump file, the function definition is in the symbol database as well (although the definition is in another header file). Is there a proper way to get this function, since it's in the symbol database?
Token is a typedef but not simplified: cppcheck does the typedef simplification beforehand, but when I output the dump file, it wasn't simplified. And again, the typedef seems to be in the symbol database (under < typdef-info > at the end of the .dump file). Is there a proper way to get this typedef info via symbol database?
Thank you very much for the help!
Last edit: Charles-the-intern 2022-10-28
Typedefs are simplified in the dump file. I guess you are looking at the "rawtokens"? You shoulld look at the "tokenlist"
code
Dumpfile:
@danielmarjamaki
No, I'm looking at the tokenlist section... but for this problem seems like I found out the reason why:
I notices, in the .dump file, that because function is inline, the return type (as part of function interface) is foo; even though inside the function definition it's still returning the original, actual type fooooo
Does cppcheck deliberate do this?
Last edit: Charles-the-intern 2022-10-31
there is a missing semicolon in your code example at the end of the first line.
sorry about the example... I meant to put the semicolon there as well.
dump file:
if you're available, can you verify if this is a bug or cppcheck deliberately do this?
That is a bug. I have created this bug ticket: https://trac.cppcheck.net/ticket/11373
Regarding the typedef issue, a big reason why it wasn't working in my case is because of the setup where we have a few #includes inside
namespace A {}AND extensive use of a precompiled header that specifies usingnamespace Afor all translation units that include this precompiled header. The precompiled header, along with its recursively included headers, are all included correctly, but seems like these #includes being inside namespace causes the issue.... perhaps this is also the reason why some tokens are not recognized as function properly
Last edit: Charles-the-intern 2022-10-31
Maybe you have found some other bug. Can you create a small example code? It should not matter that a #include is inside a namespace the preprocessor does not care about that.
Please find below the attachments as an example. There're 2 issues but they're caused by the same reason: typdef is not simplified (different from above example) and token is not recognized as function.
I noticed that if you don't do the
using namespaceand instead explicitly use the scope resolution::, everything works.main.h
header.h
main.cpp
.dump
Thank you very much for logging these tickets! I know these issues probably won't get fixed before next release, still I look forward to the next version!
Last edit: Charles-the-intern 2022-11-08
@danielmarjamaki
sorry to bother you, but I was wondering if you can verify with the above example that it's a bug?
Thanks very much!