Reputation: 1
I created a console app using VS2010 like below
int test(int i)
{
if ( i == 0 )
return 0;
else
return 1;
int j = 2;
j++;
return j;
}
void deadCode(char * pa)
{
printf("%s", pa);
}
int _tmain(int argc, _TCHAR* argv[])
{
test(2);
return 0;
}
I checked "Enable Code Analysis for C/C++ on Build" and select Rule Set "Microsoft All Rules", when I built the project, I got
1>RunCodeAnalysis:
1> Running Code Analysis...
1> Code Analysis Complete -- 0 error(s), 0 warning(s)
I expected "CA1804" warning for bold part in test(), another warning should be displayed for dead code deadCode().
My question is Why Code Analysis did not catch the defects? I also tried to created my rule set that only enabled CA1804 warning, but the result is same as above (Microsoft All Rules).
Any Ideas?
Upvotes: 0
Views: 159
Reputation: 16253
if/else
block can't be reached. But even if it did a full analysis, I would expect a "dead code" warning for the part of test()
after the if
block, not an "unused local" warning - if the code were reachable, j
would be used.Upvotes: 1