On 19.01.2024 07:18, Herman ten Brugge via Tinycc-devel wrote:
I wanted to avoid an extra check for ';' because I found code like:

     case xxx: ; }

Instead of writing 'break;' they used ';'.
Without checking for ';' a warning was printed:

Always same problem: we want something and do something else.

Anyway, what you told tcc is to accept declarations instead of
an expression, alternatively:

-                } else {
+                } else if (!decl(VT_JMP)) {
                     gexpr();
                     vpop();


Which is what happens.  Current tcc accepts:

    if (x)
        int y;
    else
        int z;

So how about the next patch:
C23: Implement declaration after label (see attached patch)

    block_after_label:
            ...
            if (tok != ':')
                decl(VT_LOCAL);
            if (tok != '}')
                goto again;
            /* we accept this, but it is a mistake */
            tcc_warning_c(warn_all)("deprecated use of label...

Yes, I'd read this as "accept declarations after a label", too.
So it might be what you want, but is it C23?

Because then, to have a declaration where it was not possible
previously, we'd now just need to put a label in front:

Not accepted
      if (x)
          int n;
          for (n = 0; n < x; ++n)
               ;
      else ...

Accepted:
      if (x)
          decl_please: int n;
          for (n = 0; n < x; ++n)
               ;
       else ...

I'd think that feels a bit strange, because the label would not
serve any purpose other than to support the declaration.

And of course, if that is C23, then people then will start to
write this.

-- gr

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to