[Bug c++/21837] New: C++/C99 standard violation in for loop

2005-05-31 Thread ahelm at gmx dot net
C++ standard quote:

3.3.2, paragraph 4:
Names declared in the for-init-statement, and in the condition of if, while,
for, and switch statements are local to the if, while, for, or switch statement
(including the controlled statement), and shall not be re-declared in a
subsequent condition of that statement nor in the outermost block (or, for the
if statement, any of the outermost blocks) of the controlled statement; see 6.4.

However g++/gcc happily compiles:

#include 

int main(void)
{
  for(int i=2;i<4;i++)
  {
int j = i;
int i;
i = 555;
printf("%d %d\n", i, j);
  }
  return 0;
}

and allows re-declaration of i. 
No warning/remark/error is given.
This should trigger an error.
Maybe it could be a gcc extension to the standard(s), but then it should
be clearly marked as such.

The C99 standard is a bit less clear about this but I believe this should also
apply to C99. 

Command lines used:
gxx -W -Wall -ansi -pedantic main.cpp
gcc -W -Wall -std=c99 -pedantic main.c

-- 
   Summary: C++/C99 standard violation in for loop
   Product: gcc
   Version: 4.0.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ahelm at gmx dot net
CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: DJGPP
GCC target triplet: MS-DOS


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21837


Re: [Bug c++/21837] New: C++/C99 standard violation in for loop

2005-05-31 Thread Gabriel Dos Reis
"ahelm at gmx dot net" <[EMAIL PROTECTED]> writes:

| C++ standard quote:
| 
| 3.3.2, paragraph 4:
| Names declared in the for-init-statement, and in the condition of if, while,
| for, and switch statements are local to the if, while, for, or switch 
statement
| (including the controlled statement), and shall not be re-declared in a
| subsequent condition of that statement nor in the outermost block (or, for the
| if statement, any of the outermost blocks) of the controlled statement; see 
6.4.
| 
| However g++/gcc happily compiles:
| 
| #include 
| 
| int main(void)
| {
|   for(int i=2;i<4;i++)
|   {
| int j = i;
| int i;

There is duplicate of this bug in the case of C++, see PR2288.