[cfe-dev] Static Analysis Warning?

Michael Price - Dev michael.b.price.dev at gmail.com
Fri Aug 27 15:39:12 PDT 2010


Consider:

#define FLOOR 1
#define CEILING 1

int main (int argc, const char * argc[])
{
     printf("Hello, World! %d\n", useFloor() ? FLOOR : CEILING);

     return 0;
}

where useFloor() returns a bool.

I would NOT want that flagged with a warning.

> int main (int argc, const char * argv[]) {
>    // insert code here...
>    printf("Hello, World! %d\n", argc == 42 ? VAL1 : VAL1);
>    return 0;
> }


On Aug 27, 2010, at 4:24 PM, Bill Wendling <wendling at apple.com> 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?
>
> -bw
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list