[llvm-bugs] [Bug 51931] New: -Wdeclaration-after-statement doesn't work when used with -std=c99

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 21 14:07:28 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51931

            Bug ID: 51931
           Summary: -Wdeclaration-after-statement doesn't work when used
                    with -std=c99
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: luka.kudra at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

-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:
https://stackoverflow.com/questions/69270600/how-to-force-werror-declaration-after-statement-with-std-c99-in-clang

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210921/fdec2388/attachment.html>


More information about the llvm-bugs mailing list