Ronny Soak - 2020-10-06

Defining a function with a default parameter, the AST comes out differently depending on if the default param is the first and only or the second parameter.
void foo(int* param = 0)
If it's the first parameter, the first operand of the "=" is "param".
void foo(int bar, int* param = 0)
If it's the second param, the first parameter of the "=" is the "*", which confuses the rule check for MISRA-C-2012 rule 11_9.

The dump looks like this:
(look for astOperand1="0x2979be0" for str="=" in the 3rd to last line , which is the token id of str="param")

<token id="0x2979820" file="test.cpp" linenr="440" column="6" str="foo" scope="0x282bc90" type="name" function="0x2c0eea0" astParent="0x2979910"/>
    <token id="0x2979910" file="test.cpp" linenr="440" column="16" str="(" scope="0x282bc90" link="0x2979eb0" astOperand1="0x2979820" astOperand2="0x2979cd0" valueType-type="void"/>
    <token id="0x2979a00" file="test.cpp" linenr="440" column="17" str="int" scope="0x282bc90" type="name"/>
    <token id="0x2979af0" file="test.cpp" linenr="440" column="20" str="*" scope="0x282bc90" type="op" isArithmeticalOp="True"/>
    <token id="0x2979be0" file="test.cpp" linenr="440" column="22" str="param" scope="0x282bc90" type="name" varId="138" variable="0x2c20e10" astParent="0x2979cd0" valueType-type="int" valueType-sign="signed" valueType-pointer="1"/>
    <token id="0x2979cd0" file="test.cpp" linenr="440" column="30" str="=" scope="0x282bc90" type="op" isAssignmentOp="True" astParent="0x2979910" astOperand1="0x2979be0" astOperand2="0x2979dc0" valueType-type="int" valueType-sign="signed" valueType-pointer="1"/>
    <token id="0x2979dc0" file="test.cpp" linenr="440" column="32" str="0" scope="0x282bc90" type="number" isInt="True" values="0x27f3a30" astParent="0x2979cd0" valueType-type="int" valueType-sign="signed"/>
    <token id="0x2979eb0" file="test.cpp" linenr="440" column="33" str=")" scope="0x282bc90" link="0x2979910"/>

for the second function:
(look for astOperand1="0x29cf860" for str="=" on the 3rd to last line, which is the token id of str="*")

<token id="0x29cf2c0" file="test.cpp" linenr="451" column="6" str="foo" scope="0x282bc90" type="name" function="0x2c0f220" astParent="0x29cf3b0"/>
    <token id="0x29cf3b0" file="test.cpp" linenr="451" column="18" str="(" scope="0x282bc90" link="0x29cfc20" astOperand1="0x29cf2c0" astOperand2="0x29cf680" valueType-type="void"/>
    <token id="0x29cf4a0" file="test.cpp" linenr="451" column="19" str="int" scope="0x282bc90" type="name"/>
    <token id="0x29cf590" file="test.cpp" linenr="451" column="23" str="bar" scope="0x282bc90" type="name" varId="143" variable="0x2c20ef0" astParent="0x29cf680" valueType-type="int" valueType-sign="signed"/>
    <token id="0x29cf680" file="test.cpp" linenr="451" column="28" str="," scope="0x282bc90" astParent="0x29cf3b0" astOperand1="0x29cf590" astOperand2="0x29cfa40"/>
    <token id="0x29cf770" file="test.cpp" linenr="451" column="30" str="int" scope="0x282bc90" type="name" astParent="0x29cf860"/>
    <token id="0x29cf860" file="test.cpp" linenr="451" column="33" str="*" scope="0x282bc90" type="op" isArithmeticalOp="True" astParent="0x29cfa40" astOperand1="0x29cf770" astOperand2="0x29cf950"/>
    <token id="0x29cf950" file="test.cpp" linenr="451" column="35" str="p_param" scope="0x282bc90" type="name" varId="144" variable="0x2c20fd0" astParent="0x29cf860" valueType-type="int" valueType-sign="signed" valueType-pointer="1"/>
    <token id="0x29cfa40" file="test.cpp" linenr="451" column="43" str="=" scope="0x282bc90" type="op" isAssignmentOp="True" astParent="0x29cf680" astOperand1="0x29cf860" astOperand2="0x29cfb30"/>
    <token id="0x29cfb30" file="test.cpp" linenr="451" column="45" str="0" scope="0x282bc90" type="number" isInt="True" values="0x28014e0" astParent="0x29cfa40" valueType-type="int" valueType-sign="signed"/>
    <token id="0x29cfc20" file="test.cpp" linenr="451" column="46" str=")" scope="0x282bc90" link="0x29cf3b0"/>

Has this a higher meaning I'm not aware of or is this a bug in the AST generation?