On 1/17/24 16:15, grischka wrote:
On 15.01.2024 00:34, Brad Robinson via Tinycc-devel wrote:
Hey All,

First post here.  Firstly, thank you all for your work on this project.  I discovered tcc just a month or so ago and really enjoying using it as a back-end code generator for a custom scripting language I'm working on.

Anyway, I noticed this small bug:

A variable declaration as the first statement in a switch case block fails when it shouldn't:

         case 1:
             int z = 123;        // This fails with "identifier expected"
             break;

Hi,

well, yes, no.  As a fact, a variable declaration is not a
statement.

There's a pretty easy workaround, just insert an empty statement before.

         case 1:
             ;                   // This fixes it
             int z = 123;
             break;


Yes, label before statement is allowed, also label before empty
statement, just not label before no statement.

As for example "label: }" is not allowed either (in the theory).

See also what gcc has to say:

test.c: In function 'main':
test.c:7:23: error: a label can only be part of a statement and a declaration is not a statement
    switch(a) case 1: int z;
                      ^~~

Which of course if a lot better than just "identifier expected"
I would agree that far.

That depends on the version of gcc / clang.
Gcc 13.2.1 prints no error.
Clang 17.0.6 prints "error: expected expression"
Clang 18.0.0(not released yet) prints "warning: label followed by a declaration is a C23 extension [-Wc23-extensions]"

I probably should have mentioned it when committing the fix.

    Herman



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

Reply via email to