tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Variable declaration as first statement in a 'case' b


From: Herman ten Brugge
Subject: Re: [Tinycc-devel] Variable declaration as first statement in a 'case' block gives error.
Date: Sun, 21 Jan 2024 11:22:30 +0100
User-agent: Mozilla Thunderbird

On 1/20/24 09:30, grischka wrote:
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.

Thanks for this long mail.

The first patch I made was clearly not correct,
The second patch was more correct but allowed too much.
I hope the third patch is more acceptable. I now only allow
declaration after label if it is inside a '{...}'.
C23: Implement declaration after label (see attached patch)

I now see another problem between gcc and clang.
The code:

   if (x) int a;
   if (x) label: int a;

Is now accepted by clang 18.0.0(pre release)
gcc >= 13.2.1 (and now tcc) and clang 17.0.6 do not allow this.

    Herman






Attachment: patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]