On Jun 25, 2011, at 1:24 AM, Jasper van de Gronde wrote:
On 2011-06-25 8:05, Campbell Barton wrote:
Hi, I was trying to compile inkscape with clang, and for many reasons this failed, however one looks like it should probably be fixed in the code.
src/ui/widget/registered-widget.h
operator const Gtk::Widget () { return dynamic_castGtk::Widget*(this); }
Should either be: operator const Gtk::Widget () { return *dynamic_castGtk::Widget*(this); } Or: operator const Gtk::Widget () { return dynamic_castGtk::Widget(this);
I'm actually a little surprised that it returns a COPY of a Gtk::Widget. It might be more appropriate to return a Gtk::Widget pointer. But in any case I'm a little surprised that this isn't caught using gcc, which makes we wonder whether this is used at all.
Well, my first reaction when seeing that is to think "aren't we following features of the C++ language itself? Why do we even need a cast?"
operator const Gtk::Widget() { return *this; }
The next thought was on a copy-ness itself. Being const might prevent visible issues, or we might just be lucky. I would think that in general a better solution would be to return a const *reference* to the type, instead of a point or a copy.
Or... do we even need such an operator? Was it perhaps a work-around for some earlier compiler's lack of full template support? gcc 4.2.1 seems quite happy without it.