According to the MISRA feature matrix, the MISRA add-on for cppcheck should check rule 5.3, which states that an identifier declared in an inner scope shall not hide an identifier declared in an outer scope. However, I don't get any issues reported when I check the following code:
t-misra.c:5:13:style:Localvariable'i'shadowsoutervariable[shadowVariable]int16_ti;^t-misra.c:3:11:note:Shadoweddeclarationint16_ti;^t-misra.c:5:13:note:Shadowvariableint16_ti;^t-misra.c:6:7:style:Variable'i'isassignedavaluethatisneverused.[unreadVariable]i=3;^t-misra.c:3:11:style:Unusedvariable:i[unusedVariable]int16_ti;^t-misra.c:1:6:style:misraviolation(use--rule-texts=<file> to get proper output) [misra-c2012-8.4]voidfn1(void)^
It seems the first 3 comments refers to this rule, 5.3, and last comment refers to other rule, and it seems to be ok.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
According to the MISRA feature matrix, the MISRA add-on for cppcheck should check rule 5.3, which states that an identifier declared in an inner scope shall not hide an identifier declared in an outer scope. However, I don't get any issues reported when I check the following code:
I am running this using:
where my misra.json file looks like this:
Am I not running the add-on correctly?
Can you add the
--enable=style
please this particular warning is provided by core cppcheck and I think the message id is shadowVariable.Looks like there has been a regression in cppcheck since https://github.com/chrchr-github/cppcheck/commit/3ef1212448aab2197ca8b58099b86fee68665c36
Last edit: CHR 2022-05-04
I have checked also your file, t.c, with option
--enable=style
:and it returns just:
Being "misra.jon":
Regarding 5.3 rule, this is not checked by Misra addon, it is checked by cppcheck itself, as it states here: http://cppcheck.net/misra.php
BTW, I take a pure example from MISRA pdf:
And, running the same command, it returns:
It seems the first 3 comments refers to this rule, 5.3, and last comment refers to other rule, and it seems to be ok.
The problem in cppcheck has been fixed with https://github.com/danmar/cppcheck/pull/4079
Thanks CHR!