Bug 72784 - declarations following executable statements in C are compiled.
Summary: declarations following executable statements in C are compiled.
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc3
Version: 8.0
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-08-27 19:49 UTC by Pawel Salek
Modified: 2007-04-18 16:46 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-10-03 03:13:35 UTC
Embargoed:


Attachments (Terms of Use)

Description Pawel Salek 2002-08-27 19:49:03 UTC
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:
Always

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
error.

Comment 1 Pawel Salek 2002-08-27 19:53:49 UTC
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-03 03:13:35 UTC
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.