Bug 72784 - declarations following executable statements in C are compiled.
declarations following executable statements in C are compiled.
Product: Red Hat Linux
Classification: Retired
Component: gcc3 (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2002-08-27 15:49 EDT by Pawel Salek
Modified: 2007-04-18 12:46 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-02 23:13:35 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Pawel Salek 2002-08-27 15:49:03 EDT
Description of problem:
Standard C requires that all declarations must preceed executable statements
(while in C++ this requirement is relaxed). gcc-3.2-1 accepts code that does not
fulfill that condition, even with -std=c89. This may make developers believe
that they write standard-conforming code while they not.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. compile following program:
#include <stdio.h>
int main(void)
        printf("Executable statement.\n");
        int n = 1;
        return n;


Actual Results:  Program compiles.

Expected Results:  Compiler should abort compilation.

Additional info:

a). Compiling with --pedantic produces a warning:
gcc -std=c89 --pedantic order.c
order.c: In function `main':
order.c:5: warning: ISO C89 forbids mixed declarations and code

An error should be produced even without --pedantic flag.

b). FWIW, older compilers did not have problem with recognizing this issue as an
Comment 1 Pawel Salek 2002-08-27 15:53:49 EDT
The gcc.info says that:
"to obtain all the diagnostics required by the
standard, you should also specify `-pedantic' (or `-pedantic-errors' if
you want them to be errors rather than warnings).  *Note Options
Controlling C Dialect: C Dialect Options."

I think it is too liberal interpretation of standard and I cannot think of a
situation when one would use -std=xxx option without requesting all the diagnostics.
Comment 2 Richard Henderson 2004-10-02 23:13:35 EDT
This change was rejected upstream in http://gcc.gnu.org/PR5957

Note You need to log in before you can comment on or make changes to this bug.