https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122579

            Bug ID: 122579
           Summary: Misleading message "‘for’ loop initial declarations
                    are only allowed in C99 or C11 mode"
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Keith.S.Thompson at gmail dot com
  Target Milestone: ---

I believe this bug exists in all recent versions of gcc since the introduction
of C17 support.

When I compile the following:

int main(void) {
    for (int i = 0; i < 10; i ++) {
        continue;
    }
}

with "gcc -std=c90 -pedantic -c c.c", I get this error (using gcc 13.3.0 on
Ubuntu as an example):

c.c: In function ‘main’:
c.c:2:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11
mode
    2 |     for (int i = 0; i < 10; i ++) {
      |     ^~~
c.c:2:5: note: use option ‘-std=c99’, ‘-std=gnu99’, ‘-std=c11’ or ‘-std=gnu11’
to compile your code

The error message is out of date; for loop initial declarations are allowed in
C99, C11, C17, and C23 (and eventually later standards). I suggest something
like "error: ‘for’ loop initial declarations are not allowed in C90 mode". I
suggest that C94/C95 mode ("-std=iso9899:199409") is not worth mentioning in
the error message.

The note is also out of date. Furthermore, compiling the code with no "std=..."
option is another way to compile the code (this wasn't true when the message
was first written and the default was "-std=gnu90"). I don't have a suggestion
for how to reword the note, except that it should be more generic rather than
listing all the relevant standards.

The gcc/*/*.po files will have to be updated with new translations. (Some of
the existing translations are inconsistent.)

Reply via email to