Red Hat Bugzilla – Bug 72784
declarations following executable statements in C are compiled.
Last modified: 2007-04-18 12:46:05 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):
Steps to Reproduce:
1. compile following program:
int n = 1;
Actual Results: Program compiles.
Expected Results: Compiler should abort compilation.
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
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.
This change was rejected upstream in http://gcc.gnu.org/PR5957