if use cppcheck to check to code like this
const int IDL1=13; enum class example { IDL1 = 16, };
CB_IDL1 will have the same varid in tokelist unexpectly,the two variable IDL1 is 1 both in that case;
<?xml version="1.0"?> <dumps> <platform name="Native" char_bit="8" short_bit="16" int_bit="32" long_bit="64" long_long_bit="64" pointer_bit="64"/> <rawtokens> <file index="0" name="test.cpp"/> <tok fileIndex="0" linenr="8" col="1" str="const"/> <tok fileIndex="0" linenr="8" col="7" str="int"/> <tok fileIndex="0" linenr="8" col="11" str="IDL1"/> <tok fileIndex="0" linenr="8" col="15" str="="/> <tok fileIndex="0" linenr="8" col="16" str="13"/> <tok fileIndex="0" linenr="8" col="18" str=";"/> <tok fileIndex="0" linenr="9" col="1" str="enum"/> <tok fileIndex="0" linenr="9" col="6" str="class"/> <tok fileIndex="0" linenr="9" col="12" str="example"/> <tok fileIndex="0" linenr="10" col="1" str="{"/> <tok fileIndex="0" linenr="11" col="5" str="IDL1"/> <tok fileIndex="0" linenr="11" col="10" str="="/> <tok fileIndex="0" linenr="11" col="12" str="16"/> <tok fileIndex="0" linenr="11" col="14" str=","/> <tok fileIndex="0" linenr="12" col="1" str="}"/> <tok fileIndex="0" linenr="12" col="2" str=";"/> </rawtokens> <suppressions> </suppressions> <dump cfg=""> <standards> <c version="c11"/> <cpp version="c++20"/> </standards> <directivelist> </directivelist> <tokenlist> <token id="0x9a04f0" file="test.cpp" linenr="8" col="1" str="const" scope="0x9a5aa0" type="name"/> <token id="0x9a0490" file="test.cpp" linenr="8" col="7" str="int" scope="0x9a5aa0" type="name"/> <token id="0x9a0430" file="test.cpp" linenr="8" col="11" str="IDL1" scope="0x9a5aa0" type="name" varId="1" variable="0x9a5be0" values="0x9a0640" astParent="0x9a0280" valueType-type="int" valueType-sign="signed" valueType-constness="1"/> <token id="0x9a0280" file="test.cpp" linenr="8" col="15" str="=" scope="0x9a5aa0" type="op" isAssignmentOp="True" astOperand1="0x9a0430" astOperand2="0x9a0220" valueType-type="int" valueType-sign="signed" valueType-constness="1"/> <token id="0x9a0220" file="test.cpp" linenr="8" col="16" str="13" scope="0x9a5aa0" type="number" isInt="True" values="0x9a06e0" astParent="0x9a0280" valueType-type="int" valueType-sign="signed"/> <token id="0x9a01c0" file="test.cpp" linenr="8" col="18" str=";" scope="0x9a5aa0"/> <token id="0x9a0160" file="test.cpp" linenr="9" col="1" str="enum" scope="0x9a5aa0" type="name"/> <token id="0x9a0040" file="test.cpp" linenr="9" col="6" str="class" scope="0x9a5aa0" type="name"/> <token id="0x99da90" file="test.cpp" linenr="9" col="12" str="example" scope="0x9a5aa0" type="name" type-scope="0x9a50a0"/> <token id="0x99da30" file="test.cpp" linenr="10" col="1" str="{" scope="0x9a50a0" link="0x99d5f0"/> <token id="0x99d880" file="test.cpp" linenr="11" col="5" str="IDL1" scope="0x9a50a0" type="name" varId="1" variable="0x9a5be0" values="0x9a05f0" astParent="0x99d820" valueType-type="int" valueType-sign="signed" valueType-typeScope="0x9a50a0"/> <token id="0x99d820" file="test.cpp" linenr="11" col="10" str="=" scope="0x9a50a0" type="op" isAssignmentOp="True" astOperand1="0x99d880" astOperand2="0x99d7c0" valueType-type="int" valueType-sign="signed" valueType-typeScope="0x9a50a0"/> <token id="0x99d7c0" file="test.cpp" linenr="11" col="12" str="16" scope="0x9a50a0" type="number" isInt="True" values="0x9a0690" astParent="0x99d820" valueType-type="int" valueType-sign="signed"/> <token id="0x99d650" file="test.cpp" linenr="11" col="14" str="," scope="0x9a50a0"/> <token id="0x99d5f0" file="test.cpp" linenr="12" col="1" str="}" scope="0x9a50a0" link="0x99da30"/> <token id="0x99d590" file="test.cpp" linenr="12" col="2" str=";" scope="0x9a5aa0"/> </tokenlist> <scopes> <scope id="0x9a5aa0" type="Global"> <varlist> <var id="0x9a5be0"/> </varlist> </scope> <scope id="0x9a50a0" type="Enum" className="example" bodyStart="0x99da30" bodyEnd="0x99d5f0" nestedIn="0x9a5aa0"/> </scopes> <variables> <var id="0x9a5be0" nameToken="0x9a0430" typeStartToken="0x9a0490" typeEndToken="0x9a0490" access="Global" scope="0x9a5aa0" constness="1" isArgument="false" isArray="false" isClass="false" isConst="true" isExtern="false" isLocal="false" isPointer="false" isReference="false" isStatic="false"/> </variables> <valueflow> <values id="0x9a0640"> <value intvalue="13" known="true"/> </values> <values id="0x9a06e0"> <value intvalue="13" known="true"/> </values> <values id="0x9a05f0"> <value intvalue="13" known="true"/> </values> <values id="0x9a0690"> <value intvalue="16" known="true"/> </values> </valueflow> </dump> </dumps>
it will case some problems in some cases,such as Scope::addEnum(symbolddatabase.cpp,line3614) will return nullptr then case syntax error
This is a major bug. Thanks for reporting it! I created this ticket: https://trac.cppcheck.net/ticket/9180
Thanks!
Log in to post a comment.
if use cppcheck to check to code like this
CB_IDL1 will have the same varid in tokelist unexpectly,the two variable IDL1 is 1 both in that case;
it will case some problems in some cases,such as Scope::addEnum(symbolddatabase.cpp,line3614) will return nullptr then case syntax error
This is a major bug. Thanks for reporting it! I created this ticket: https://trac.cppcheck.net/ticket/9180
Thanks!