Nope, l: } is legal K&R but not legal ANSI-C and C99.  Sparse is right.

Tommy



Steve French said:
> I ran into a bug in sparse when I added a label for a goto.  I changed
> the code I was planning to add to avoid it (by adding a continue at the
> bottom of the loop) but it shows that there is a bug in parsing goto
> labels.  The sparse version is current (at least matches the one that
> was in sparse.bkbits.net).  The sparse tool generated the following:
>
> test.c:15:2: warning: Expected ; at end of statement
> test.c:15:2: warning: got }
> builtin:0:0: warning: Expected } at end of compound statement
> builtin:0:0: warning: got end-of-input
> builtin:0:0: warning: Expected } at end of function
> builtin:0:0: warning: got end-of-input
>
> You can see it from the following tests which differ in only one line
> (the 1st generates the warning, the second does not).
>
> void some_junk_function_with_sparse_error(void)
> {
>         int i;
>         int j = 0;
>
>         while(j!=2) {
>                 for(i=0;i<10;i++) {
>                         if(i==9) {
>                                 j = 1;
>                                 goto out;
>                         }
>                 }
>                 j = 2;
> out:
>         }
> }
>
>
>
> The error can be avoided by adding a superflous continue statement e.g.
>
> void some_junk_function_without_sparse_error(void)
> {
>         int i;
>         int j = 0;
>
>         while(j!=2) {
>                 for(i=0;i<10;i++) {
>                         if(i==9) {
>                                 j = 1;
>                                 goto out;
>                         }
>                 }
>                 j = 2;
> out:
>                 continue;
>         }
> }
>
> which is ugly.  As an aside, I hate gotos, but the kind of case I was
> dealing with was someting C did not provide - ie a way to use break or
> continue as if we were in the outer while loop while inside the inner
> for loop.  It can be coded differently, but it ends up with longer code
> - and while I was debating which was less ugly (to use goto or not), I
> hit the sparse bug which the junk code above demonstrates.
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to [EMAIL PROTECTED]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to