[cfe-dev] Static Analysis Warning?

Dale Johannesen dalej at apple.com
Fri Aug 27 15:14:59 PDT 2010


On Aug 27, 2010, at 2:24 PMPDT, Bill Wendling wrote:

> Consider this code:
>
> #include <stdio.h>
>
> enum Foo {
>  VAL1,
>  VAL2
> };
>
> int main (int argc, const char * argv[]) {
>    // insert code here...
>    printf("Hello, World! %d\n", argc == 42 ? VAL1 : VAL1);
>    return 0;
> }
>
> When I run the static analyzer on it, it doesn't warn. But the coder  
> might not have meant for both values of the ?: operator to be the  
> same. Do you think it's worth a static analyzer warning?

If a human wrote that it would probably be an error, although this  
does occur in test suites (all compilers here do the optimization).   
The question is whether things like that would arise in machine- 
generated code or after macro expansion often enough for false  
positives to be annoying.   I would guess no, and vote for the warning.




More information about the cfe-dev mailing list