[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#151065: g++: destructor called twice



The segmentation fault is a bug in your code, not in gcc.  A temporary
is getting constructed, and you are using the compiler generated
assignment operator, so you get two instances deallocating the same
memory. Try adding a private operator=

  class ScalarVector : public Vector<ScalarVector> {
  private:
     ScalarVector& operator=(const ScalarVector&);
  };

and your code will fail to compile.  Provide a suitable public
operator= and your code should work.


I believe the other problem can be simplified to

struct A {
   double operator*(double);
};

template<typename T> T operator*(double, T);

int main() {
   A a;
   a * 3.0;
}

which gives the error
z2.cc: In function `int main()':
z2.cc:5: `T operator*(double, const T&) [with T = double]' must have an 
   argument of class or enumerated type

-- 
Philip


-- 
To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: