This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/5957: gcc accepts C99-only code even when -std=c89 arg used
- From: jason-gccprs at molenda dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 14 Mar 2002 03:02:09 -0000
- Subject: c/5957: gcc accepts C99-only code even when -std=c89 arg used
- Reply-to: jason-gccprs at molenda dot com
>Number: 5957
>Category: c
>Synopsis: gcc accepts C99-only code even when -std=c89 arg used
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Mar 13 19:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Jason Molenda
>Release: gcc-3_1-branch
>Organization:
>Environment:
>Description:
When gcc is given a source file like the following:
#include <stdio.h>
int main () { puts ("hi"); int f; }
which is invalid in ISO C89 or the 1994 Amendment, it will accept the code even if -std=c89 is given on the command line. If -pedantic is added, it will issue a pedwarn,
ISO C89 forbids mixed declarations and code
but I'd argue that this is not sufficient. If I pass -std=c89 to gcc, I expect that the code which compiles will also compile for Bob down the hall, who is stubborn and refuses to upgrade beyond gcc 2.95. I can understand that gcc can't provide a genuinely ISO C89 environment when C99-only headers may be present, but it should be able to handle this one.
Inside gcc, the flag_isoc94, flag_isoc99 variables which one might try to use to catch this error, seem to be intended only to indicate additional capabilities that should be recognized. i.e. I don't see a way in c-parse.in to detect that the user is requesting a specifically restricted set of C constructs with the current set of flags.
gcc 3.1's behavior in this case by default is also confusing. I guess gcc is in "g89" mode by default, so if you need to add "-std=c99" to explicitly put yourself in ISO C99 mode. But you can use C99 features like variable-decls-after-statements-in-a-block in the "g89" mode (which wouldn't have worked with 2.95's g89 mode).
>How-To-Repeat:
>Fix:
Recognize in c-decl.c when the user is explicitly asking for c89 or c94 mode, and issue an error() when c99-specific constructs are used in the source.
>Release-Note:
>Audit-Trail:
>Unformatted: