[Bug c++/22446] New: Invocation of destructor of element of array changes vtable

2005-07-12 Thread Forest dot Rouse at ansys dot com
.ii is so long hangs emacs) ---
#include 

class A
{
private:
int a;
public:
A(int iA=1) : a(iA) {}
A(const A& iA) { *this = iA; }
A& operator=(const A& iA) {
if (this != &iA) {
a = iA.a;
}
return *this;
}
virtual ~A() {}
virtual int GetA() const;
void SetA(int iA) { a = iA; }
virtual void CompBugIt() const;

friend int operator==(const A& iA, const A& iB) {
return (iA.a == iB.a);
}

friend int operator != (const A& iA, const A& iB) {
return !(iA == iB);
}
};

int A::GetA() const { return a; }

void A::CompBugIt() const
{
std::cout << "In A's CompBugIt: " << a;
}

class B : public A
{
private:
int b;
public:
B(int iA=1, int iB=2) : A(iA), b(iB) {}
B(const B& iB) : A() { *this = iB; }
B& operator=(const B& iB) {
if (this != &iB) {
A::operator=(iB);
b = iB.b;
}
return *this;
}
~B() {}

void CompBugIt() const;
};

void B::CompBugIt() const
{
std::cout << "In B's CompBugIt: " << b << " ";
A::CompBugIt();
}

int
main(int argc, char **argv)
{
int i;
B test[10];
for (i = 0; i < 10; i++) {
B b(i, 10*i);
test[i] = b;
}

for (i = 0; i < 9; i++) {
test[i].CompBugIt();
std::cout << std::endl;
}

B temp[10];
for (i = 0; i < 10; i++) temp[i] = test[i];

for (i = 0; i < 10; i++) {
test[i].~B();
}

for (i = 9; i >= 0; i--) {
B b = temp[i];
test[9-i] = b;
}

for (i = 0; i < 9; i++) {
test[i].CompBugIt();
std::cout << std::endl;
}
    
    return 0;
}

--------- last try with .ii -------

-- just hung emacs had to kill it. --

-- 
   Summary: Invocation of destructor of element of array changes
vtable
   Product: gcc
   Version: 3.4.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Forest dot Rouse at ansys dot com
CC: Forest dot Rouse at ansys dot com,gcc-bugs at gcc dot
gnu dot org


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


[Bug c++/22446] Invocation of destructor of element of array changes vtable

2005-07-12 Thread Forest dot Rouse at ansys dot com

--- Additional Comments From Forest dot Rouse at ansys dot com  2005-07-12 
20:39 ---
Created an attachment (id=9252)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9252&action=view)
preprocessed file


-- 


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