This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/20180] New: Scope error using constructor argument with assignment-like syntax


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]