Bug 18770 - g++ accepts invalid code with scopes on ifs
g++ accepts invalid code with scopes on ifs
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
3.4.2
: P2 normal
: ---
Assigned To: Not yet assigned to anyone
: accepts-invalid
: 31956 37728 38345 39038 41965 (view as bug list)
Depends on: 2288
Blocks: 12944
  Show dependency treegraph
 
Reported: 2004-12-01 23:05 UTC by Stefan Seefeld
Modified: 2011-06-05 02:09 UTC (History)
9 users (show)

See Also:
Host: GNU/Linux x86
Target: GNU/Linux x86
Build: GNU/Linux x86
Known to work:
Known to fail:
Last reconfirmed: 2005-05-29 14:42:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Seefeld 2004-12-01 23:05:48 UTC
According to ISO/IEC 14882 6.4-3, the following snippet is ill-formed:

if (int x = 1)
{
  int x = 2; // redeclaration of x
}

Yet the g++ versions that come with Fedora Core 3 accept it.
Specifically, these versions are:

gcc version 3.3.4 20040817 (Red Hat Linux 3.3.4-2)
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
gcc version 4.0.0 20041019 (Red Hat 4.0.0-0.8)
Comment 1 Andrew Pinski 2004-12-01 23:21:37 UTC
Note this is the full testcase:
void f()
{
if (int x = 1)
{
  int x = 2; // redeclaration of x
}
}

Confirmed,  This is related to PR 2288.
Comment 2 Andrew Pinski 2008-10-03 18:46:04 UTC
*** Bug 37728 has been marked as a duplicate of this bug. ***
Comment 3 Argiris Kirtzidis 2008-10-08 09:09:47 UTC
Note that the same rule applies to the 'switch' statement too:

switch (int x = 1)
{
  default:
  int x = 2; // there should be an error because of redeclaration
}
Comment 4 Jonathan Wakely 2008-12-02 10:39:32 UTC
*** Bug 38345 has been marked as a duplicate of this bug. ***
Comment 5 Wolfgang Bangerth 2009-01-30 15:05:32 UTC
*** Bug 39038 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2009-11-06 07:52:47 UTC
*** Bug 41965 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2009-12-08 20:24:04 UTC
*** Bug 31956 has been marked as a duplicate of this bug. ***
Comment 8 Nathan Froyd 2011-06-05 02:09:41 UTC
This bug was fixed on trunk in r174307; the automated update was not done because something was wonky with my email.  Closing.