<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -Wdeclaration-after-statement doesn't work when used with -std=c99"
   href="https://bugs.llvm.org/show_bug.cgi?id=51931">51931</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wdeclaration-after-statement doesn't work when used with -std=c99
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>luka.kudra@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>-Wdeclaration-after-statement doesn't do anything if combined with -std=c99 or
newer.

Take a look at the following program:

// prog.c
#include <stdio.h>

int main(void)
{
    printf("hello world\n");
    int i = 0;

    return 0;
}

If I compile it with clang with the following command:

$ clang -std=c99 -Wdeclaration-after-statement prog.c

it produces no warnings.

If I compile the same code with gcc with the following command:

$ gcc -std=c99 -Wdeclaration-after-statement prog.c

it produces the following warning:

prog.c: In function ‘main’:
prog.c:6:9: warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]
    6 |         int i = 0;
      |         ^~~

This is the behavior I would like to have with clang, but it only produces this
warning if I use it with -std=c90 or -std=c89 or -ansi, like this:

$ clang -std=c90 -Wdeclaration-after-statement prog.c
prog.c:6:6: warning: ISO C90 forbids mixing declarations and code
[-Wdeclaration-after-statement]
        int i = 0;
            ^
1 warning generated.


I asked this question on stackoverflow because I thought I was using the flags
in a wrong way but it turns that -Wdeclaration-after-statement just doesn't
work with clang in the scenario that I'm using it.
You can take a look at the question on the following link:
<a href="https://stackoverflow.com/questions/69270600/how-to-force-werror-declaration-after-statement-with-std-c99-in-clang">https://stackoverflow.com/questions/69270600/how-to-force-werror-declaration-after-statement-with-std-c99-in-clang</a>

To summarize -Wdeclaration-after-statement doesn't work with -std=c99 on clang,
but it works on gcc.

I tested this on Arch Linux with clang version 12.0.1.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>