The patch currently issues a false positive for the test case
below. I suspect the chain might need to be cleared after each
condition that involves a side-effect.

   int foo (int a)
   {
     if (a) return 1; else if (++a) return 2; else if (a) return 3;
     return 0;
   }

But the last branch here can never be reached, right?  If a == 0, foo
returns 2, otherwise it just returns 1.  So I think we should diagnose
this.

It probably wasn't the best example. The general issue here is
that the second condition has a side-effect that can change (in
this case clearly does) the value of the expression.

Here's a better example:

    int a;

    int bar (void) { a = 1; return 0; }

    int foo (void) {
        if (a) return 1;
        else if (foo ()) return 2;
        else if (a) return 3;
        return 0;
    }

Since we don't know bar's side-effects we must assume they change
the value of a and so we must avoid diagnosing the third if.

Martin

Reply via email to