GNOME Bugzilla – Bug 117494
GCC 3.3.1 static_cast compile error
Last modified: 2004-12-22 21:47:04 UTC
gtkmm has issues with GCC 3.3.1 gtk/gtkmm/treeiter.cc:145 return static_cast<const TreeNodeChildren&>(static_cast<const TreeIter&>(*this)); is an invalid static_cast (the outer one) I'm trying return reinterpret_cast<const TreeNodeChildren&>(*this); for the debian package right now, hoping that was what you intended with that line of code (which is an "adventuresome move" ;) ) The second issue is already #ifdef'ed for GCC 3.3.0, but it might be in later gcc versions as well (since gcc is getting stricter!) glib/glibmm/ustring.h:523
Does gcc 3.2.3 fix this? Is it available to your version of debian? I have the gcc 3.2.2 RedHat 9 and do not have this problem. If you can show us the exact error then we can maybe understand this better. If you have some solution that you have actualyl compiled that could help too. I don't really see the problem. TreeRow and TreeNodeChildren inherit from TreeIter.
GCC 3.3.x is newer than 3.2 and stricter enforcing some things. First one: In file included from ../../glib/glibmm/exception.h:25, from ../../glib/glibmm/error.h:28, from ../../glib/glibmm/convert.h:29, from convert.cc:3: ../../glib/glibmm/ustring.h:536: error: `template<class In, class ValueType = typename std::iterator_traits<_Iterator>::value_type> struct Glib::ustring::SequenceToString' is private ../../glib/glibmm/ustring.h:555: error: within this context ../../glib/glibmm/ustring.h:536: error: `template<class In, class ValueType = typename std::iterator_traits<_Iterator>::value_type> struct Glib::ustring::SequenceToString' is private ../../glib/glibmm/ustring.h:561: error: within this context To the second issue: > TreeRow and TreeNodeChildren inherit from TreeIter That is correct, but you are casting TreeRow -> TreeIter -> TreeNodeChildren. The first is a correct static cast afaik, but the second one is not. A TreeIter is not (necessarily) a TreeNodeChildren. I'm not sure if, but maybe g++ would accept this if TreeNodeChildren had an initialization function making a TreeNodeChildren out of a TreeIter. treeiter.cc: In member function `const Gtk::TreeNodeChildren& Gtk::TreeRow::children() const': treeiter.cc:145: error: invalid static_cast from type `const Gtk::TreeIter&' to type `const Gtk::TreeNodeChildren&'
You are right, the first one apparently is a GCC 3.3.1 pre bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10849 Not sure about the second one though.
In return static_cast<const TreeNodeChildren&>(static_cast<const TreeIter&>(*this)); We cast from TreeRow to TreeIter (legal because TreeRow derives from TreeIter) from TreeIter to TreeRowChildren (legal because TreeRowChildren derives from TreeIter). > A TreeIter is not (necessarily) a TreeNodeChildren. That's why we do a cast. So, I don't see any problem with this. However, maybe it's a problem that TreeNodeChildren inherits _private_ly from TreeIter. Could you try changing that, on line 249 if treeiter.h. please.
And sorry for my versioning confusion.
changing class TreeNodeChildren : private TreeIter to class TreeNodeChildren : public TreeIter has no effect.
Maybe you could trying splitting the casts over 2 or 3 lines to find out exactly where the problem is.
The error message already states which cast it does not accept. It's the outer one. I also posted the solution i'm using in the Non-Maintainer-Package i uploaded: reinterpret_cast<const TreeNodeChildren&>(*this); What is the original code expected to do? To my understanding, static cast means doing some conversion, like double->int (mapping 1.0 to 1) is a static cast. A reinterpret_cast doesn't change the data, but just uses a different interpretation. For example treating a double number as a bit sequence is a reinterpret_cast.
> The error message already states which cast it does not accept. > It's the outer one. Yes, but if it's a gcc bug then maybe it's only a bug in certain circumstances. Would it kill you to try? > I also posted the solution i'm using in the Non-Maintainer-Package i > uploaded: reinterpret_cast<const TreeNodeChildren&>(*this); Discussion on the list (that really should be here) suggests that dynamic_cast<> is a better alternative, though it's still not clear why static_cast<> is not working here. > What is the original code expected to do? Cast a TreeIter to a TreeNodeChildren. Not something that should be difficult.
As of GCC 3.3.1RC1 (1:3.3.1-0rc1 in debian), the static_cast works fine, and no workarounds are necessary.
Excellent news. I guess we got lucky - someone else must have submitted a bug report.