Antti-Juhani Kaijanaho: Yet another case of C++ unsafety
I was playing around with BNFC's C++ mode, and discovered that its authors have fallen prey to two of C++'s famous pitfalls:- All polymorphic classes (i.e. classes with at least one virtual function) must have a virtual destructor. Fortunately, G++ -Wall warns about this one.
- The compiler inserts a default copy constructor and a default copy
assignment operator to all classes that lack an explicit copy constructor
and an explicit copy assignment operator. This will bite you if you have
pointer members in the class, and your destructor performs a
deleteoperation on one of them. You need to either forbid copying by adding an explicit private copy constructor and an explicit private copy assignment operator to the class (prototypes without definitions will do nicely), or by enforcing some sane copying policy by giving your own copy constructor and copy assignment operator (popular policies are deep copying and sharing with reference counting).
Were you aware of these issues? :)
I fixed these problems in BNFC with this patch.
2004-05-22T23:40+0300 - /en/programming
Trackback url: http://antti-juhani.kaijanaho.info/blog/en/programming/bnfc-cpp-bug.trackback (trackback on rikki / trackback is broken)
Your Comment