Question on tree-walking and mutually-recursive types

Richard Kenner kenner@vlsi1.ultra.nyu.edu
Tue Jun 29 03:05:00 GMT 2004


walk_tree walks the type of all variables in a BIND_EXPR.  And walking
a POINTER_TYPE walks the type it points to.

But it's possible for a pointer type X to point to a pointer type Y, which
points back to X.  I don't think you can express this in C, but you can in Ada:

procedure tpself is
  type Tp1;
  type tp2 is access Tp1;
  type Tp1 is access Tp2;
  X: Tp1;
begin
   null;
end tpself;

You may ask why somebody would want to write something like that and it's a
good question, but the general rule for Ada is that if you *can* write
something, you can be sure that an ACATS test *will* try it.  In this case
it's c38102a, part of which is explicitly written just to test this case!

We go into an infinite loop here (not recursion because of WALK_SUBTREE_TAIL).

It's tempting to not go into TREE_TYPE of a POINTER_TYPE in the tree walk,
but I found out the hard way last week that issuing certain error messages
for C++ templates depends on that walk being done.

Any suggestions how to deal with this?



More information about the Gcc mailing list