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++/15797] New: static_casts of objects on stack only point to copy of object


#include <iostream>
using namespace std;
 
class base
{
  public:
    int val1;
    base():val1(10)
     {cout << "Where: "<< this << endl;}
};
 
 
class child: public base
{ public:
    int val2;
    child():val2(20)
     {cout <<  "Where: "<< this <<  endl;}
};
 
 
 
int main(void)
{
 
  child myclass;
 
 
  cout << "Where child:             " << &myclass << endl;
  cout << "Where static_cast< base> " << &(static_cast<base> (myclass)) << endl;
 
  cout << "=================="<< endl;
  cout << "Changing val1 to 11" << endl;
 
  static_cast<base>(myclass).val1=11;                   // This should change
myclass.val1;
 
  cout << "val1 in child: " << myclass.val1 << endl;   // But does not work
  cout << "val1 in base:  " << static_cast<base>(myclass).val1 << endl;
 
 
  return 0;
}

-- 
           Summary: static_casts of objects on stack only point to copy of
                    object
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: loeffel77 at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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