This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20180] New: Scope error using constructor argument with assignment-like syntax
- From: "bugzilla-t05k1 at email dot galacticnorth dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Feb 2005 19:42:45 -0000
- Subject: [Bug c++/20180] New: Scope error using constructor argument with assignment-like syntax
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When declaring a variable which hides a same-named variable from a higher scope.
If the new variable is initialized from the same-named variable using the
assignment-like constructor syntax AND there was an earlier hiding of the same
variable name...
The value used for the initialization value comes from the earlier hidden (now
out of scope) version of the variable!
Simple example:
int main()
{
int i = 1;
{ int i = 22; }
{ int i = i; cout << i << '\n'; } // Prints 22!
{ cout << i << ' '; int i = i; cout << i << '\n'; } // Prints "1 22"!!
{ int i(i); cout << i << '\n'; } // Prints 1 (as expected)
}
--
Summary: Scope error using constructor argument with assignment-
like syntax
Product: gcc
Version: 3.3.5
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bugzilla-t05k1 at email dot galacticnorth dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-pc-linux-gnu
GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20180