After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 117494 - GCC 3.3.1 static_cast compile error
GCC 3.3.1 static_cast compile error
Status: RESOLVED NOTABUG
Product: gtkmm
Classification: Bindings
Component: general
2.2
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2003-07-15 18:36 UTC by Erich Schubert
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Erich Schubert 2003-07-15 18:36:57 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
Comment 1 Murray Cumming 2003-07-16 11:49:52 UTC
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.
Comment 2 Erich Schubert 2003-07-16 12:20:47 UTC
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&'


Comment 3 Erich Schubert 2003-07-16 12:34:28 UTC
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.
Comment 4 Murray Cumming 2003-07-16 15:11:13 UTC
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.
Comment 5 Murray Cumming 2003-07-16 15:11:54 UTC
And sorry for my versioning confusion.
Comment 6 btb 2003-07-16 18:07:13 UTC
changing
class TreeNodeChildren : private TreeIter
to
class TreeNodeChildren : public TreeIter
has no effect.
Comment 7 Murray Cumming 2003-07-17 09:56:33 UTC
Maybe you could trying splitting the casts over 2 or 3 lines to find
out exactly where the problem is.
Comment 8 Erich Schubert 2003-07-17 12:06:01 UTC
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.
Comment 9 Murray Cumming 2003-07-18 04:49:47 UTC
> 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.
Comment 10 btb 2003-07-24 18:24:55 UTC
As of GCC 3.3.1RC1 (1:3.3.1-0rc1 in debian), the static_cast works
fine, and no workarounds are necessary.
Comment 11 Murray Cumming 2003-07-25 07:44:53 UTC
Excellent news. I guess we got lucky - someone else must have 
submitted a bug report.